@@ -105,7 +105,7 @@ def test_alignment_error():
105
105
106
106
107
107
@pytest .mark .parametrize ("dtype" , (float , int ))
108
- @pytest .mark .parametrize ("chunk" , [False , True ])
108
+ @pytest .mark .parametrize ("chunk" , [False , pytest . param ( True , marks = requires_dask ) ])
109
109
# TODO: make this intp when python 3.8 is dropped
110
110
@pytest .mark .parametrize ("expected_groups" , [None , [0 , 1 , 2 ], np .array ([0 , 1 , 2 ], dtype = np .int64 )])
111
111
@pytest .mark .parametrize (
@@ -145,7 +145,7 @@ def test_groupby_reduce(
145
145
) -> None :
146
146
array = array .astype (dtype )
147
147
if chunk :
148
- if not has_dask or expected_groups is None :
148
+ if expected_groups is None :
149
149
pytest .skip ()
150
150
array = da .from_array (array , chunks = (3 ,) if array .ndim == 1 else (1 , 3 ))
151
151
by = da .from_array (by , chunks = (3 ,) if by .ndim == 1 else (1 , 3 ))
@@ -166,7 +166,7 @@ def test_groupby_reduce(
166
166
engine = engine ,
167
167
)
168
168
# we use pd.Index(expected_groups).to_numpy() which is always int64
169
- # for the values in this tests
169
+ # for the values in this test
170
170
if expected_groups is None :
171
171
g_dtype = by .dtype
172
172
elif isinstance (expected_groups , np .ndarray ):
@@ -191,14 +191,20 @@ def gen_array_by(size, func):
191
191
return array , by
192
192
193
193
194
- @pytest .mark .parametrize ("chunks" , [None , - 1 , 3 , 4 ])
194
+ @pytest .mark .parametrize (
195
+ "chunks" ,
196
+ [
197
+ None ,
198
+ pytest .param (- 1 , marks = requires_dask ),
199
+ pytest .param (3 , marks = requires_dask ),
200
+ pytest .param (4 , marks = requires_dask ),
201
+ ],
202
+ )
195
203
@pytest .mark .parametrize ("nby" , [1 , 2 , 3 ])
196
204
@pytest .mark .parametrize ("size" , ((12 ,), (12 , 9 )))
197
205
@pytest .mark .parametrize ("add_nan_by" , [True , False ])
198
206
@pytest .mark .parametrize ("func" , ALL_FUNCS )
199
207
def test_groupby_reduce_all (nby , size , chunks , func , add_nan_by , engine ):
200
- if chunks is not None and not has_dask :
201
- pytest .skip ()
202
208
if "arg" in func and engine == "flox" :
203
209
pytest .skip ()
204
210
@@ -390,16 +396,16 @@ def test_numpy_reduce_nd_md():
390
396
def test_groupby_agg_dask (func , shape , array_chunks , group_chunks , add_nan , dtype , engine , reindex ):
391
397
"""Tests groupby_reduce with dask arrays against groupby_reduce with numpy arrays"""
392
398
393
- rng = np .random .default_rng (12345 )
394
- array = dask .array .from_array (rng .random (shape ), chunks = array_chunks ).astype (dtype )
395
- array = dask .array .ones (shape , chunks = array_chunks )
396
-
397
399
if func in ["first" , "last" ]:
398
400
pytest .skip ()
399
401
400
402
if "arg" in func and (engine == "flox" or reindex ):
401
403
pytest .skip ()
402
404
405
+ rng = np .random .default_rng (12345 )
406
+ array = dask .array .from_array (rng .random (shape ), chunks = array_chunks ).astype (dtype )
407
+ array = dask .array .ones (shape , chunks = array_chunks )
408
+
403
409
labels = np .array ([0 , 0 , 2 , 2 , 2 , 1 , 1 , 2 , 2 , 1 , 1 , 0 ])
404
410
if add_nan :
405
411
labels = labels .astype (float )
@@ -612,7 +618,14 @@ def test_groupby_reduce_axis_subset_against_numpy(func, axis, engine):
612
618
assert_equal (actual , expected , tolerance )
613
619
614
620
615
- @pytest .mark .parametrize ("reindex,chunks" , [(None , None ), (False , (2 , 2 , 3 )), (True , (2 , 2 , 3 ))])
621
+ @pytest .mark .parametrize (
622
+ "reindex, chunks" ,
623
+ [
624
+ (None , None ),
625
+ pytest .param (False , (2 , 2 , 3 ), marks = requires_dask ),
626
+ pytest .param (True , (2 , 2 , 3 ), marks = requires_dask ),
627
+ ],
628
+ )
616
629
@pytest .mark .parametrize (
617
630
"axis, groups, expected_shape" ,
618
631
[
@@ -624,8 +637,6 @@ def test_groupby_reduce_axis_subset_against_numpy(func, axis, engine):
624
637
def test_groupby_reduce_nans (reindex , chunks , axis , groups , expected_shape , engine ):
625
638
def _maybe_chunk (arr ):
626
639
if chunks :
627
- if not has_dask :
628
- pytest .skip ()
629
640
return da .from_array (arr , chunks = chunks )
630
641
else :
631
642
return arr
@@ -739,7 +750,14 @@ def test_npg_nanarg_bug(func):
739
750
)
740
751
@pytest .mark .parametrize ("method" , ["cohorts" , "map-reduce" ])
741
752
@pytest .mark .parametrize ("chunk_labels" , [False , True ])
742
- @pytest .mark .parametrize ("chunks" , ((), (1 ,), (2 ,)))
753
+ @pytest .mark .parametrize (
754
+ "chunks" ,
755
+ (
756
+ (),
757
+ pytest .param ((1 ,), marks = requires_dask ),
758
+ pytest .param ((2 ,), marks = requires_dask ),
759
+ ),
760
+ )
743
761
def test_groupby_bins (chunk_labels , kwargs , chunks , engine , method ) -> None :
744
762
array = [1 , 1 , 1 , 1 , 1 , 1 ]
745
763
labels = [0.2 , 1.5 , 1.9 , 2 , 3 , 20 ]
@@ -748,8 +766,6 @@ def test_groupby_bins(chunk_labels, kwargs, chunks, engine, method) -> None:
748
766
pytest .xfail ()
749
767
750
768
if chunks :
751
- if not has_dask :
752
- pytest .skip ()
753
769
array = dask .array .from_array (array , chunks = chunks )
754
770
if chunk_labels :
755
771
labels = dask .array .from_array (labels , chunks = chunks )
@@ -825,16 +841,14 @@ def test_rechunk_for_cohorts(chunk_at, expected):
825
841
assert rechunked .chunks == expected
826
842
827
843
828
- @pytest .mark .parametrize ("chunks" , [None , 3 ])
844
+ @pytest .mark .parametrize ("chunks" , [None , pytest . param ( 3 , marks = requires_dask ) ])
829
845
@pytest .mark .parametrize ("fill_value" , [123 , np .nan ])
830
846
@pytest .mark .parametrize ("func" , ALL_FUNCS )
831
847
def test_fill_value_behaviour (func , chunks , fill_value , engine ):
832
848
# fill_value = np.nan tests promotion of int counts to float
833
849
# This is used by xarray
834
850
if func in ["all" , "any" ] or "arg" in func :
835
851
pytest .skip ()
836
- if chunks is not None and not has_dask :
837
- pytest .skip ()
838
852
839
853
npfunc = _get_array_func (func )
840
854
by = np .array ([1 , 2 , 3 , 1 , 2 , 3 ])
@@ -1050,11 +1064,8 @@ def test_factorize_values_outside_bins():
1050
1064
assert_equal (expected , actual )
1051
1065
1052
1066
1053
- @pytest .mark .parametrize ("chunk" , [True , False ])
1067
+ @pytest .mark .parametrize ("chunk" , [pytest . param ( True , marks = requires_dask ) , False ])
1054
1068
def test_multiple_groupers_bins (chunk ) -> None :
1055
- if chunk and not has_dask :
1056
- pytest .skip ()
1057
-
1058
1069
xp = dask .array if chunk else np
1059
1070
array_kwargs = {"chunks" : 2 } if chunk else {}
1060
1071
array = xp .ones ((5 , 2 ), ** array_kwargs , dtype = np .int64 )
@@ -1087,9 +1098,9 @@ def test_multiple_groupers_bins(chunk) -> None:
1087
1098
np .arange (2 , 4 ).reshape (1 , 2 ),
1088
1099
],
1089
1100
)
1090
- @pytest .mark .parametrize ("chunk" , [True , False ])
1101
+ @pytest .mark .parametrize ("chunk" , [pytest . param ( True , marks = requires_dask ) , False ])
1091
1102
def test_multiple_groupers (chunk , by1 , by2 , expected_groups ) -> None :
1092
- if chunk and ( not has_dask or expected_groups is None ) :
1103
+ if chunk and expected_groups is None :
1093
1104
pytest .skip ()
1094
1105
1095
1106
xp = dask .array if chunk else np
@@ -1233,7 +1244,7 @@ def test_dtype(func, dtype, engine):
1233
1244
pytest .skip ()
1234
1245
arr = np .ones ((4 , 12 ), dtype = dtype )
1235
1246
labels = np .array (["a" , "a" , "c" , "c" , "c" , "b" , "b" , "c" , "c" , "b" , "b" , "f" ])
1236
- actual , _ = groupby_reduce (arr , labels , func = func , dtype = np .float64 )
1247
+ actual , _ = groupby_reduce (arr , labels , func = func , dtype = np .float64 , engine = engine )
1237
1248
assert actual .dtype == np .dtype ("float64" )
1238
1249
1239
1250
0 commit comments