@@ -17,6 +17,20 @@ def aggregate_all(request):
17
17
return _wrap_notimplemented_xfail (impl .aggregate , 'aggregate_' + name )
18
18
19
19
20
+ def _deselect_purepy (aggregate_all , * args , ** kwargs ):
21
+ # purepy implementations does not handle nan values and ndim correctly.
22
+ # So it needs to be excluded from several tests."""
23
+ return aggregate_all .__name__ .endswith ('purepy' )
24
+
25
+
26
+ def _deselect_purepy_and_invalid_axis (aggregate_all , size , axis , * args , ** kwargs ):
27
+ if axis >= len (size ):
28
+ return True
29
+ if aggregate_all .__name__ .endswith ('purepy' ):
30
+ # purepy does not handle axis parameter
31
+ return True
32
+
33
+
20
34
def test_preserve_missing (aggregate_all ):
21
35
res = aggregate_all (np .array ([0 , 1 , 3 , 1 , 3 ]), np .arange (101 , 106 , dtype = int ))
22
36
np .testing .assert_array_equal (res , np .array ([101 , 206 , 0 , 208 ]))
@@ -100,12 +114,14 @@ def test_array_ordering(aggregate_all, order, size=10):
100
114
assert aggregate_all (np .zeros (size , dtype = int ), mat [0 , :], order = order )[0 ] == sum (range (size ))
101
115
102
116
117
+ @pytest .mark .deselect_if (func = _deselect_purepy )
103
118
@pytest .mark .parametrize ("size" , [None , (10 , 2 )])
104
119
def test_ndim_group_idx (aggregate_all , size ):
105
120
group_idx = np .vstack ((np .repeat (np .arange (10 ), 10 ), np .repeat ([0 , 1 ], 50 )))
106
121
aggregate_all (group_idx , 1 , size = size )
107
122
108
123
124
+ @pytest .mark .deselect_if (func = _deselect_purepy )
109
125
@pytest .mark .parametrize (["ndim" , "order" ], itertools .product ([1 , 2 , 3 ], ["C" , "F" ]))
110
126
def test_ndim_indexing (aggregate_all , ndim , order , outsize = 10 ):
111
127
nindices = int (outsize ** ndim )
@@ -242,9 +258,8 @@ def test_argmin_argmax_nonans(aggregate_all):
242
258
np .testing .assert_array_equal (res , [3 , - 1 , - 1 , 5 ])
243
259
244
260
261
+ @pytest .mark .deselect_if (func = _deselect_purepy )
245
262
def test_argmin_argmax_nans (aggregate_all ):
246
- if aggregate_all .__name__ .endswith ('purepy' ):
247
- pytest .xfail ("purepy doesn't handle nan values correctly" )
248
263
if aggregate_all .__name__ .endswith ('pandas' ):
249
264
pytest .xfail ("pandas always ignores nans" )
250
265
@@ -258,9 +273,10 @@ def test_argmin_argmax_nans(aggregate_all):
258
273
np .testing .assert_array_equal (res , [3 , - 1 , - 1 , - 1 ])
259
274
260
275
276
+ @pytest .mark .deselect_if (func = _deselect_purepy )
261
277
def test_nanargmin_nanargmax_nans (aggregate_all ):
262
- if aggregate_all .__name__ .endswith ('purepy ' ):
263
- pytest .xfail ("purepy doesn't handle nan values correctly " )
278
+ if aggregate_all .__name__ .endswith ('pandas ' ):
279
+ pytest .xfail ("pandas doesn't fill indices for all- nan groups with fill_value but with -inf instead " )
264
280
265
281
group_idx = np .array ([0 , 0 , 0 , 0 , 3 , 3 , 3 , 3 ])
266
282
a = np .array ([4 , 4 , np .nan , 1 , np .nan , np .nan , np .nan , np .nan ])
@@ -339,12 +355,8 @@ def test_list_ordering(aggregate_all, order):
339
355
a = a [::- 1 ]
340
356
ref = a [:4 ]
341
357
342
- try :
343
- res = aggregate_all (group_idx , a , func = list )
344
- except NotImplementedError :
345
- pytest .xfail ("Function not yet implemented" )
346
- else :
347
- np .testing .assert_array_equal (np .array (res [0 ]), ref )
358
+ res = aggregate_all (group_idx , a , func = list )
359
+ np .testing .assert_array_equal (np .array (res [0 ]), ref )
348
360
349
361
350
362
@pytest .mark .parametrize ("order" , ["normal" , "reverse" ])
@@ -360,14 +372,6 @@ def test_sort(aggregate_all, order):
360
372
np .testing .assert_array_equal (res , ref )
361
373
362
374
363
- def _deselect_purepy_and_invalid_axis (aggregate_all , func , size , axis ):
364
- if axis >= len (size ):
365
- return True
366
- if aggregate_all .__name__ .endswith ('purepy' ):
367
- # purepy does not handle axis parameter
368
- return True
369
-
370
-
371
375
@pytest .mark .deselect_if (func = _deselect_purepy_and_invalid_axis )
372
376
@pytest .mark .parametrize ("axis" , (0 , 1 ))
373
377
@pytest .mark .parametrize ("size" , ((12 ,), (12 , 5 )))
@@ -424,6 +428,7 @@ def test_along_axis(aggregate_all, func, size, axis):
424
428
np .testing .assert_allclose (actual .squeeze (), expected )
425
429
426
430
431
+ @pytest .mark .deselect_if (func = _deselect_purepy )
427
432
def test_not_last_axis_reduction (aggregate_all ):
428
433
group_idx = np .array ([1 , 2 , 2 , 0 , 1 ])
429
434
a = np .array ([
@@ -442,8 +447,9 @@ def test_not_last_axis_reduction(aggregate_all):
442
447
np .testing .assert_allclose (expected , actual )
443
448
444
449
450
+ @pytest .mark .deselect_if (func = _deselect_purepy )
445
451
def test_custom_callable (aggregate_all ):
446
- def sum_ (x ):
452
+ def custom_callable (x ):
447
453
return x .sum ()
448
454
449
455
size = (10 ,)
@@ -453,12 +459,13 @@ def sum_(x):
453
459
a = np .random .randn (* size )
454
460
455
461
expected = a .sum (axis = axis , keepdims = True )
456
- actual = aggregate_all (group_idx , a , axis = axis , func = sum_ , fill_value = 0 )
462
+ actual = aggregate_all (group_idx , a , axis = axis , func = custom_callable , fill_value = 0 )
457
463
assert actual .ndim == a .ndim
458
464
459
465
np .testing .assert_allclose (actual , expected )
460
466
461
467
468
+ @pytest .mark .deselect_if (func = _deselect_purepy )
462
469
def test_argreduction_nD_array_1D_idx (aggregate_all ):
463
470
# https://github.com/ml31415/numpy-groupies/issues/41
464
471
group_idx = np .array ([0 , 0 , 2 , 2 , 2 , 1 , 1 , 2 , 2 , 1 , 1 , 0 ], dtype = int )
@@ -468,6 +475,7 @@ def test_argreduction_nD_array_1D_idx(aggregate_all):
468
475
np .testing .assert_equal (actual , expected )
469
476
470
477
478
+ @pytest .mark .deselect_if (func = _deselect_purepy )
471
479
def test_argreduction_negative_fill_value (aggregate_all ):
472
480
if aggregate_all .__name__ .endswith ('pandas' ):
473
481
pytest .xfail ("pandas always skips nan values" )
@@ -479,6 +487,7 @@ def test_argreduction_negative_fill_value(aggregate_all):
479
487
np .testing .assert_equal (actual , expected )
480
488
481
489
490
+ @pytest .mark .deselect_if (func = _deselect_purepy )
482
491
@pytest .mark .parametrize ("nan_inds" , (None , tuple ([[1 , 4 , 5 ], Ellipsis ]), tuple ((1 , (0 , 1 , 2 , 3 )))))
483
492
@pytest .mark .parametrize ("ddof" , (0 , 1 ))
484
493
@pytest .mark .parametrize ("func" , ("nanvar" , "nanstd" ))
0 commit comments