19
19
20
20
import pyarrow as pa
21
21
import datafusion
22
+
22
23
f = datafusion .functions
23
24
24
25
25
26
class TestCase (unittest .TestCase ):
26
-
27
27
def _prepare (self ):
28
28
ctx = datafusion .ExecutionContext ()
29
29
@@ -51,12 +51,10 @@ def test_select(self):
51
51
def test_filter (self ):
52
52
df = self ._prepare ()
53
53
54
- df = df \
55
- .select (
56
- f .col ("a" ) + f .col ("b" ),
57
- f .col ("a" ) - f .col ("b" ),
58
- ) \
59
- .filter (f .col ("a" ) > f .lit (2 ))
54
+ df = df .select (
55
+ f .col ("a" ) + f .col ("b" ),
56
+ f .col ("a" ) - f .col ("b" ),
57
+ ).filter (f .col ("a" ) > f .lit (2 ))
60
58
61
59
# execute and collect the first (and only) batch
62
60
result = df .collect ()[0 ]
@@ -66,12 +64,10 @@ def test_filter(self):
66
64
67
65
def test_sort (self ):
68
66
df = self ._prepare ()
69
- df = df .sort ([
70
- f .col ("b" ).sort (ascending = False )
71
- ])
67
+ df = df .sort ([f .col ("b" ).sort (ascending = False )])
72
68
73
69
table = pa .Table .from_batches (df .collect ())
74
- expected = {'a' : [3 , 2 , 1 ], 'b' : [6 , 5 , 4 ]}
70
+ expected = {"a" : [3 , 2 , 1 ], "b" : [6 , 5 , 4 ]}
75
71
self .assertEqual (table .to_pydict (), expected )
76
72
77
73
def test_limit (self ):
@@ -111,10 +107,8 @@ def test_join(self):
111
107
df1 = ctx .create_dataframe ([[batch ]])
112
108
113
109
df = df .join (df1 , on = "a" , how = "inner" )
114
- df = df .sort ([
115
- f .col ("a" ).sort (ascending = True )
116
- ])
110
+ df = df .sort ([f .col ("a" ).sort (ascending = True )])
117
111
table = pa .Table .from_batches (df .collect ())
118
112
119
- expected = {'a' : [1 , 2 ], 'c' : [8 , 10 ], 'b' : [4 , 5 ]}
113
+ expected = {"a" : [1 , 2 ], "c" : [8 , 10 ], "b" : [4 , 5 ]}
120
114
self .assertEqual (table .to_pydict (), expected )
0 commit comments