@@ -154,7 +154,7 @@ def test_multi_index_groupby_sum() -> None:
154154
155155
156156@requires_pandas_ge_2_2
157- def test_multi_index_propagation ():
157+ def test_multi_index_propagation () -> None :
158158 # regression test for GH9648
159159 times = pd .date_range ("2023-01-01" , periods = 4 )
160160 locations = ["A" , "B" ]
@@ -2291,7 +2291,7 @@ def test_resample_origin(self) -> None:
22912291 times = pd .date_range ("2000-01-01T02:03:01" , freq = "6h" , periods = 10 )
22922292 array = DataArray (np .arange (10 ), [("time" , times )])
22932293
2294- origin = "start"
2294+ origin : Literal [ "start" ] = "start"
22952295 actual = array .resample (time = "24h" , origin = origin ).mean ()
22962296 expected = DataArray (array .to_series ().resample ("24h" , origin = origin ).mean ())
22972297 assert_identical (expected , actual )
@@ -2696,7 +2696,7 @@ def test_default_flox_method() -> None:
26962696
26972697@requires_cftime
26982698@pytest .mark .filterwarnings ("ignore" )
2699- def test_cftime_resample_gh_9108 ():
2699+ def test_cftime_resample_gh_9108 () -> None :
27002700 import cftime
27012701
27022702 ds = Dataset (
@@ -3046,7 +3046,7 @@ def test_gappy_resample_reductions(reduction):
30463046 assert_identical (expected , actual )
30473047
30483048
3049- def test_groupby_transpose ():
3049+ def test_groupby_transpose () -> None :
30503050 # GH5361
30513051 data = xr .DataArray (
30523052 np .random .randn (4 , 2 ),
@@ -3106,7 +3106,7 @@ def test_lazy_grouping(grouper, expect_index):
31063106
31073107
31083108@requires_dask
3109- def test_lazy_grouping_errors ():
3109+ def test_lazy_grouping_errors () -> None :
31103110 import dask .array
31113111
31123112 data = DataArray (
@@ -3132,15 +3132,15 @@ def test_lazy_grouping_errors():
31323132
31333133
31343134@requires_dask
3135- def test_lazy_int_bins_error ():
3135+ def test_lazy_int_bins_error () -> None :
31363136 import dask .array
31373137
31383138 with pytest .raises (ValueError , match = "Bin edges must be provided" ):
31393139 with raise_if_dask_computes ():
31403140 _ = BinGrouper (bins = 4 ).factorize (DataArray (dask .array .arange (3 )))
31413141
31423142
3143- def test_time_grouping_seasons_specified ():
3143+ def test_time_grouping_seasons_specified () -> None :
31443144 time = xr .date_range ("2001-01-01" , "2002-01-01" , freq = "D" )
31453145 ds = xr .Dataset ({"foo" : np .arange (time .size )}, coords = {"time" : ("time" , time )})
31463146 labels = ["DJF" , "MAM" , "JJA" , "SON" ]
@@ -3149,7 +3149,36 @@ def test_time_grouping_seasons_specified():
31493149 assert_identical (actual , expected .reindex (season = labels ))
31503150
31513151
3152- def test_groupby_multiple_bin_grouper_missing_groups ():
3152+ def test_multiple_grouper_unsorted_order () -> None :
3153+ time = xr .date_range ("2001-01-01" , "2003-01-01" , freq = "MS" )
3154+ ds = xr .Dataset ({"foo" : np .arange (time .size )}, coords = {"time" : ("time" , time )})
3155+ labels = ["DJF" , "MAM" , "JJA" , "SON" ]
3156+ actual = ds .groupby (
3157+ {
3158+ "time.season" : UniqueGrouper (labels = labels ),
3159+ "time.year" : UniqueGrouper (labels = [2002 , 2001 ]),
3160+ }
3161+ ).sum ()
3162+ expected = (
3163+ ds .groupby ({"time.season" : UniqueGrouper (), "time.year" : UniqueGrouper ()})
3164+ .sum ()
3165+ .reindex (season = labels , year = [2002 , 2001 ])
3166+ )
3167+ assert_identical (actual , expected .reindex (season = labels ))
3168+
3169+ b = xr .DataArray (
3170+ np .random .default_rng (0 ).random ((2 , 3 , 4 )),
3171+ coords = {"x" : [0 , 1 ], "y" : [0 , 1 , 2 ]},
3172+ dims = ["x" , "y" , "z" ],
3173+ )
3174+ actual2 = b .groupby (
3175+ x = UniqueGrouper (labels = [1 , 0 ]), y = UniqueGrouper (labels = [2 , 0 , 1 ])
3176+ ).sum ()
3177+ expected2 = b .reindex (x = [1 , 0 ], y = [2 , 0 , 1 ]).transpose ("z" , ...)
3178+ assert_identical (actual2 , expected2 )
3179+
3180+
3181+ def test_groupby_multiple_bin_grouper_missing_groups () -> None :
31533182 from numpy import nan
31543183
31553184 ds = xr .Dataset (
@@ -3226,7 +3255,7 @@ def test_shuffle_by(chunks, expected_chunks):
32263255
32273256
32283257@requires_dask
3229- def test_groupby_dask_eager_load_warnings ():
3258+ def test_groupby_dask_eager_load_warnings () -> None :
32303259 ds = xr .Dataset (
32313260 {"foo" : (("z" ), np .arange (12 ))},
32323261 coords = {"x" : ("z" , np .arange (12 )), "y" : ("z" , np .arange (12 ))},
0 commit comments