@@ -2848,20 +2848,25 @@ def test_multiple_groupers(use_flox) -> None:
2848
2848
xy = UniqueGrouper (labels = ["a" , "b" , "c" ]),
2849
2849
eagerly_compute_group = eagerly_compute_group ,
2850
2850
)
2851
+ expected = xr .DataArray (
2852
+ [[[1 , 1 , 1 ], [np .nan , 1 , 2 ]]] * 4 ,
2853
+ dims = ("z" , "x" , "xy" ),
2854
+ coords = {"xy" : ("xy" , ["a" , "b" , "c" ], {"foo" : "bar" })},
2855
+ )
2851
2856
with raise_if_dask_computes (max_computes = 1 ):
2852
2857
if eagerly_compute_group :
2853
2858
with pytest .warns (DeprecationWarning ):
2854
2859
gb = b .groupby (** kwargs ) # type: ignore[arg-type]
2860
+ assert_identical (gb .count (), expected )
2855
2861
else :
2856
2862
gb = b .groupby (** kwargs ) # type: ignore[arg-type]
2857
2863
assert is_chunked_array (gb .encoded .codes .data )
2858
2864
assert not gb .encoded .group_indices
2859
- expected = xr .DataArray (
2860
- [[[1 , 1 , 1 ], [np .nan , 1 , 2 ]]] * 4 ,
2861
- dims = ("z" , "x" , "xy" ),
2862
- coords = {"xy" : ("xy" , ["a" , "b" , "c" ], {"foo" : "bar" })},
2863
- )
2864
- assert_identical (gb .count (), expected )
2865
+ if has_flox :
2866
+ assert_identical (gb .count (), expected )
2867
+ else :
2868
+ with pytest .raises (ValueError , match = "when lazily grouping" ):
2869
+ gb .count ()
2865
2870
2866
2871
2867
2872
@pytest .mark .parametrize ("use_flox" , [True , False ])
@@ -3003,11 +3008,6 @@ def test_lazy_grouping(grouper, expect_index):
3003
3008
pd .testing .assert_index_equal (encoded .full_index , expect_index )
3004
3009
np .testing .assert_array_equal (encoded .unique_coord .values , np .array (expect_index ))
3005
3010
3006
- lazy = (
3007
- xr .Dataset ({"foo" : data }, coords = {"zoo" : data })
3008
- .groupby (zoo = grouper , eagerly_compute_group = False )
3009
- .count ()
3010
- )
3011
3011
eager = (
3012
3012
xr .Dataset ({"foo" : data }, coords = {"zoo" : data .compute ()})
3013
3013
.groupby (zoo = grouper )
@@ -3017,9 +3017,16 @@ def test_lazy_grouping(grouper, expect_index):
3017
3017
{"foo" : (encoded .codes .name , np .ones (encoded .full_index .size ))},
3018
3018
coords = {encoded .codes .name : expect_index },
3019
3019
)
3020
- assert_identical (eager , lazy )
3021
3020
assert_identical (eager , expected )
3022
3021
3022
+ if has_flox :
3023
+ lazy = (
3024
+ xr .Dataset ({"foo" : data }, coords = {"zoo" : data })
3025
+ .groupby (zoo = grouper , eagerly_compute_group = False )
3026
+ .count ()
3027
+ )
3028
+ assert_identical (eager , lazy )
3029
+
3023
3030
3024
3031
@requires_dask
3025
3032
def test_lazy_grouping_errors ():
0 commit comments