@@ -28,9 +28,9 @@ def run(ctx):
28
28
result = executor .run ([Group ([(1 ,), (5 ,), (6 ,)])], exa )
29
29
assert result == [Group ([(1 ,), (5 ,), (6 ,)])]
30
30
31
+
31
32
def test_emit_single_column_none ():
32
33
def udf_wrapper ():
33
-
34
34
def run (ctx ):
35
35
ctx .emit (None )
36
36
@@ -46,11 +46,11 @@ def run(ctx):
46
46
result = executor .run ([Group ([(1 ,), (5 ,), (6 ,)])], exa )
47
47
assert result == [Group ([(None ,)])]
48
48
49
+
49
50
def test_emit_multi_column_none ():
50
51
def udf_wrapper ():
51
-
52
52
def run (ctx ):
53
- ctx .emit (None ,None )
53
+ ctx .emit (None , None )
54
54
55
55
executor = UDFMockExecutor ()
56
56
meta = MockMetaData (
@@ -63,7 +63,8 @@ def run(ctx):
63
63
)
64
64
exa = MockExaEnvironment (meta )
65
65
result = executor .run ([Group ([(1 ,), (5 ,), (6 ,)])], exa )
66
- assert result == [Group ([(None ,None )])]
66
+ assert result == [Group ([(None , None )])]
67
+
67
68
68
69
def test_next_emit_reset ():
69
70
def udf_wrapper ():
@@ -75,7 +76,7 @@ def run(ctx):
75
76
break
76
77
ctx .reset ()
77
78
while True :
78
- ctx .emit (ctx .t + 1 )
79
+ ctx .emit (ctx .t + 1 )
79
80
if not ctx .next ():
80
81
break
81
82
@@ -91,6 +92,7 @@ def run(ctx):
91
92
result = executor .run ([Group ([(1 ,), (5 ,), (6 ,)])], exa )
92
93
assert result == [Group ([(1 ,), (5 ,), (6 ,), (2 ,), (6 ,), (7 ,)])]
93
94
95
+
94
96
def test_next_reset_combined ():
95
97
def udf_wrapper ():
96
98
@@ -101,7 +103,7 @@ def run(ctx):
101
103
break
102
104
ctx .next (reset = True )
103
105
for i in range (2 ):
104
- ctx .emit (ctx .t + 1 )
106
+ ctx .emit (ctx .t + 1 )
105
107
if not ctx .next ():
106
108
break
107
109
@@ -115,7 +117,7 @@ def run(ctx):
115
117
)
116
118
exa = MockExaEnvironment (meta )
117
119
result = executor .run ([Group ([(1 ,), (5 ,), (6 ,)])], exa )
118
- assert result == [Group ([(1 ,), (5 ,),(2 ,), (6 ,)])]
120
+ assert result == [Group ([(1 ,), (5 ,), (2 ,), (6 ,)])]
119
121
120
122
121
123
def test_get_dataframe_all ():
@@ -185,9 +187,168 @@ def run(ctx):
185
187
result = executor .run ([Group ([(1 ,), (2 ,), (3 ,), (4 ,), (5 ,), (6 ,)])], exa )
186
188
assert result == [Group ([(1 ,), (2 ,), (4 ,), (5 ,)])]
187
189
188
- def test_emit_tuple_exception ():
190
+
191
+ def test_get_dataframe_num_rows_1 ():
192
+ def udf_wrapper ():
193
+ def run (ctx ):
194
+ df = ctx .get_dataframe (num_rows = 1 )
195
+ ctx .emit (df )
196
+
197
+ executor = UDFMockExecutor ()
198
+ meta = MockMetaData (
199
+ script_code_wrapper_function = udf_wrapper ,
200
+ input_type = "SET" ,
201
+ input_columns = [Column ("t" , int , "INTEGER" )],
202
+ output_type = "EMITS" ,
203
+ output_columns = [Column ("t" , int , "INTEGER" )]
204
+ )
205
+ exa = MockExaEnvironment (meta )
206
+ result = executor .run ([Group ([(1 ,), (2 ,), (3 ,), (4 ,), (5 ,), (6 ,)])], exa )
207
+ assert result == [Group ([(1 ,), ])]
208
+
209
+
210
+ def test_get_dataframe_num_rows_0 ():
211
+ def udf_wrapper ():
212
+ def run (ctx ):
213
+ df = ctx .get_dataframe (num_rows = 0 )
214
+
215
+ executor = UDFMockExecutor ()
216
+ meta = MockMetaData (
217
+ script_code_wrapper_function = udf_wrapper ,
218
+ input_type = "SET" ,
219
+ input_columns = [Column ("t" , int , "INTEGER" )],
220
+ output_type = "EMITS" ,
221
+ output_columns = [Column ("t" , int , "INTEGER" )]
222
+ )
223
+ exa = MockExaEnvironment (meta )
224
+ with pytest .raises (RuntimeError ) as excinfo :
225
+ result = executor .run ([Group ([(1 ,), (2 ,), (3 ,), (4 ,), (5 ,), (6 ,)])], exa )
226
+
227
+
228
+ def test_get_dataframe_num_rows_float ():
229
+ def udf_wrapper ():
230
+ def run (ctx ):
231
+ df = ctx .get_dataframe (num_rows = 1.5 )
232
+
233
+ executor = UDFMockExecutor ()
234
+ meta = MockMetaData (
235
+ script_code_wrapper_function = udf_wrapper ,
236
+ input_type = "SET" ,
237
+ input_columns = [Column ("t" , int , "INTEGER" )],
238
+ output_type = "EMITS" ,
239
+ output_columns = [Column ("t" , int , "INTEGER" )]
240
+ )
241
+ exa = MockExaEnvironment (meta )
242
+ with pytest .raises (RuntimeError ) as excinfo :
243
+ result = executor .run ([Group ([(1 ,), (2 ,), (3 ,), (4 ,), (5 ,), (6 ,)])], exa )
244
+
245
+ def test_get_dataframe_num_rows_None ():
246
+ def udf_wrapper ():
247
+ def run (ctx ):
248
+ df = ctx .get_dataframe (num_rows = None )
249
+
250
+ executor = UDFMockExecutor ()
251
+ meta = MockMetaData (
252
+ script_code_wrapper_function = udf_wrapper ,
253
+ input_type = "SET" ,
254
+ input_columns = [Column ("t" , int , "INTEGER" )],
255
+ output_type = "EMITS" ,
256
+ output_columns = [Column ("t" , int , "INTEGER" )]
257
+ )
258
+ exa = MockExaEnvironment (meta )
259
+ with pytest .raises (RuntimeError ) as excinfo :
260
+ result = executor .run ([Group ([(1 ,), (2 ,), (3 ,), (4 ,), (5 ,), (6 ,)])], exa )
261
+
262
+
263
+ def test_get_dataframe_num_rows_negative ():
264
+ def udf_wrapper ():
265
+ def run (ctx ):
266
+ df = ctx .get_dataframe (num_rows = - 1 )
267
+
268
+ executor = UDFMockExecutor ()
269
+ meta = MockMetaData (
270
+ script_code_wrapper_function = udf_wrapper ,
271
+ input_type = "SET" ,
272
+ input_columns = [Column ("t" , int , "INTEGER" )],
273
+ output_type = "EMITS" ,
274
+ output_columns = [Column ("t" , int , "INTEGER" )]
275
+ )
276
+ exa = MockExaEnvironment (meta )
277
+ with pytest .raises (RuntimeError ) as excinfo :
278
+ result = executor .run ([Group ([(1 ,), (2 ,), (3 ,), (4 ,), (5 ,), (6 ,)])], exa )
279
+
280
+ def test_get_dataframe_start_col_None ():
281
+ def udf_wrapper ():
282
+ def run (ctx ):
283
+ df = ctx .get_dataframe (num_rows = 10 , start_col = None )
284
+
285
+ executor = UDFMockExecutor ()
286
+ meta = MockMetaData (
287
+ script_code_wrapper_function = udf_wrapper ,
288
+ input_type = "SET" ,
289
+ input_columns = [Column ("t" , int , "INTEGER" )],
290
+ output_type = "EMITS" ,
291
+ output_columns = [Column ("t" , int , "INTEGER" )]
292
+ )
293
+ exa = MockExaEnvironment (meta )
294
+ with pytest .raises (RuntimeError ) as excinfo :
295
+ result = executor .run ([Group ([(1 ,), (2 ,), (3 ,), (4 ,), (5 ,), (6 ,)])], exa )
296
+
297
+ def test_get_dataframe_start_col_negative ():
298
+ def udf_wrapper ():
299
+ def run (ctx ):
300
+ df = ctx .get_dataframe (num_rows = 10 , start_col = - 1 )
301
+
302
+ executor = UDFMockExecutor ()
303
+ meta = MockMetaData (
304
+ script_code_wrapper_function = udf_wrapper ,
305
+ input_type = "SET" ,
306
+ input_columns = [Column ("t" , int , "INTEGER" )],
307
+ output_type = "EMITS" ,
308
+ output_columns = [Column ("t" , int , "INTEGER" )]
309
+ )
310
+ exa = MockExaEnvironment (meta )
311
+ with pytest .raises (RuntimeError ) as excinfo :
312
+ result = executor .run ([Group ([(1 ,), (2 ,), (3 ,), (4 ,), (5 ,), (6 ,)])], exa )
313
+
314
+ def test_get_dataframe_start_col_0 ():
189
315
def udf_wrapper ():
316
+ def run (ctx ):
317
+ df = ctx .get_dataframe (num_rows = 1 , start_col = 0 )
318
+ ctx .emit (df )
319
+
320
+ executor = UDFMockExecutor ()
321
+ meta = MockMetaData (
322
+ script_code_wrapper_function = udf_wrapper ,
323
+ input_type = "SET" ,
324
+ input_columns = [Column ("t" , int , "INTEGER" )],
325
+ output_type = "EMITS" ,
326
+ output_columns = [Column ("t" , int , "INTEGER" )]
327
+ )
328
+ exa = MockExaEnvironment (meta )
329
+ result = executor .run ([Group ([(1 ,), (2 ,), (3 ,), (4 ,), (5 ,), (6 ,)])], exa )
330
+ assert result == [Group ([(1 ,), ])]
190
331
332
+ def test_get_dataframe_start_col_positive ():
333
+ def udf_wrapper ():
334
+ def run (ctx ):
335
+ df = ctx .get_dataframe (num_rows = 1 , start_col = 1 )
336
+ ctx .emit (df )
337
+
338
+ executor = UDFMockExecutor ()
339
+ meta = MockMetaData (
340
+ script_code_wrapper_function = udf_wrapper ,
341
+ input_type = "SET" ,
342
+ input_columns = [Column ("t" , int , "INTEGER" )],
343
+ output_type = "EMITS" ,
344
+ output_columns = [Column ("t" , int , "INTEGER" )]
345
+ )
346
+ exa = MockExaEnvironment (meta )
347
+ result = executor .run ([Group ([(1 ,), (2 ,), (3 ,), (4 ,), (5 ,), (6 ,)])], exa )
348
+ assert result == [Group ([(1 ,), ])]
349
+
350
+ def test_emit_tuple_exception ():
351
+ def udf_wrapper ():
191
352
def run (ctx ):
192
353
while True :
193
354
ctx .emit ((1 ,))
0 commit comments