@@ -158,7 +158,7 @@ def test_multi_index_groupby_sum() -> None:
158
158
159
159
160
160
@requires_pandas_ge_2_2
161
- def test_multi_index_propagation ():
161
+ def test_multi_index_propagation () -> None :
162
162
# regression test for GH9648
163
163
times = pd .date_range ("2023-01-01" , periods = 4 )
164
164
locations = ["A" , "B" ]
@@ -2295,7 +2295,7 @@ def test_resample_origin(self) -> None:
2295
2295
times = pd .date_range ("2000-01-01T02:03:01" , freq = "6h" , periods = 10 )
2296
2296
array = DataArray (np .arange (10 ), [("time" , times )])
2297
2297
2298
- origin = "start"
2298
+ origin : Literal [ "start" ] = "start"
2299
2299
actual = array .resample (time = "24h" , origin = origin ).mean ()
2300
2300
expected = DataArray (array .to_series ().resample ("24h" , origin = origin ).mean ())
2301
2301
assert_identical (expected , actual )
@@ -2700,7 +2700,7 @@ def test_default_flox_method() -> None:
2700
2700
2701
2701
@requires_cftime
2702
2702
@pytest .mark .filterwarnings ("ignore" )
2703
- def test_cftime_resample_gh_9108 ():
2703
+ def test_cftime_resample_gh_9108 () -> None :
2704
2704
import cftime
2705
2705
2706
2706
ds = Dataset (
@@ -3050,7 +3050,7 @@ def test_gappy_resample_reductions(reduction):
3050
3050
assert_identical (expected , actual )
3051
3051
3052
3052
3053
- def test_groupby_transpose ():
3053
+ def test_groupby_transpose () -> None :
3054
3054
# GH5361
3055
3055
data = xr .DataArray (
3056
3056
np .random .randn (4 , 2 ),
@@ -3110,7 +3110,7 @@ def test_lazy_grouping(grouper, expect_index):
3110
3110
3111
3111
3112
3112
@requires_dask
3113
- def test_lazy_grouping_errors ():
3113
+ def test_lazy_grouping_errors () -> None :
3114
3114
import dask .array
3115
3115
3116
3116
data = DataArray (
@@ -3136,15 +3136,15 @@ def test_lazy_grouping_errors():
3136
3136
3137
3137
3138
3138
@requires_dask
3139
- def test_lazy_int_bins_error ():
3139
+ def test_lazy_int_bins_error () -> None :
3140
3140
import dask .array
3141
3141
3142
3142
with pytest .raises (ValueError , match = "Bin edges must be provided" ):
3143
3143
with raise_if_dask_computes ():
3144
3144
_ = BinGrouper (bins = 4 ).factorize (DataArray (dask .array .arange (3 )))
3145
3145
3146
3146
3147
- def test_time_grouping_seasons_specified ():
3147
+ def test_time_grouping_seasons_specified () -> None :
3148
3148
time = xr .date_range ("2001-01-01" , "2002-01-01" , freq = "D" )
3149
3149
ds = xr .Dataset ({"foo" : np .arange (time .size )}, coords = {"time" : ("time" , time )})
3150
3150
labels = ["DJF" , "MAM" , "JJA" , "SON" ]
@@ -3153,7 +3153,36 @@ def test_time_grouping_seasons_specified():
3153
3153
assert_identical (actual , expected .reindex (season = labels ))
3154
3154
3155
3155
3156
- def test_groupby_multiple_bin_grouper_missing_groups ():
3156
+ def test_multiple_grouper_unsorted_order () -> None :
3157
+ time = xr .date_range ("2001-01-01" , "2003-01-01" , freq = "MS" )
3158
+ ds = xr .Dataset ({"foo" : np .arange (time .size )}, coords = {"time" : ("time" , time )})
3159
+ labels = ["DJF" , "MAM" , "JJA" , "SON" ]
3160
+ actual = ds .groupby (
3161
+ {
3162
+ "time.season" : UniqueGrouper (labels = labels ),
3163
+ "time.year" : UniqueGrouper (labels = [2002 , 2001 ]),
3164
+ }
3165
+ ).sum ()
3166
+ expected = (
3167
+ ds .groupby ({"time.season" : UniqueGrouper (), "time.year" : UniqueGrouper ()})
3168
+ .sum ()
3169
+ .reindex (season = labels , year = [2002 , 2001 ])
3170
+ )
3171
+ assert_identical (actual , expected .reindex (season = labels ))
3172
+
3173
+ b = xr .DataArray (
3174
+ np .random .default_rng (0 ).random ((2 , 3 , 4 )),
3175
+ coords = {"x" : [0 , 1 ], "y" : [0 , 1 , 2 ]},
3176
+ dims = ["x" , "y" , "z" ],
3177
+ )
3178
+ actual2 = b .groupby (
3179
+ x = UniqueGrouper (labels = [1 , 0 ]), y = UniqueGrouper (labels = [2 , 0 , 1 ])
3180
+ ).sum ()
3181
+ expected2 = b .reindex (x = [1 , 0 ], y = [2 , 0 , 1 ]).transpose ("z" , ...)
3182
+ assert_identical (actual2 , expected2 )
3183
+
3184
+
3185
+ def test_groupby_multiple_bin_grouper_missing_groups () -> None :
3157
3186
from numpy import nan
3158
3187
3159
3188
ds = xr .Dataset (
@@ -3230,7 +3259,7 @@ def test_shuffle_by(chunks, expected_chunks):
3230
3259
3231
3260
3232
3261
@requires_dask
3233
- def test_groupby_dask_eager_load_warnings ():
3262
+ def test_groupby_dask_eager_load_warnings () -> None :
3234
3263
ds = xr .Dataset (
3235
3264
{"foo" : (("z" ), np .arange (12 ))},
3236
3265
coords = {"x" : ("z" , np .arange (12 )), "y" : ("z" , np .arange (12 ))},
0 commit comments