@@ -154,7 +154,7 @@ def test_multi_index_groupby_sum() -> None:
154
154
155
155
156
156
@requires_pandas_ge_2_2
157
- def test_multi_index_propagation ():
157
+ def test_multi_index_propagation () -> None :
158
158
# regression test for GH9648
159
159
times = pd .date_range ("2023-01-01" , periods = 4 )
160
160
locations = ["A" , "B" ]
@@ -2291,7 +2291,7 @@ def test_resample_origin(self) -> None:
2291
2291
times = pd .date_range ("2000-01-01T02:03:01" , freq = "6h" , periods = 10 )
2292
2292
array = DataArray (np .arange (10 ), [("time" , times )])
2293
2293
2294
- origin = "start"
2294
+ origin : Literal [ "start" ] = "start"
2295
2295
actual = array .resample (time = "24h" , origin = origin ).mean ()
2296
2296
expected = DataArray (array .to_series ().resample ("24h" , origin = origin ).mean ())
2297
2297
assert_identical (expected , actual )
@@ -2696,7 +2696,7 @@ def test_default_flox_method() -> None:
2696
2696
2697
2697
@requires_cftime
2698
2698
@pytest .mark .filterwarnings ("ignore" )
2699
- def test_cftime_resample_gh_9108 ():
2699
+ def test_cftime_resample_gh_9108 () -> None :
2700
2700
import cftime
2701
2701
2702
2702
ds = Dataset (
@@ -3046,7 +3046,7 @@ def test_gappy_resample_reductions(reduction):
3046
3046
assert_identical (expected , actual )
3047
3047
3048
3048
3049
- def test_groupby_transpose ():
3049
+ def test_groupby_transpose () -> None :
3050
3050
# GH5361
3051
3051
data = xr .DataArray (
3052
3052
np .random .randn (4 , 2 ),
@@ -3106,7 +3106,7 @@ def test_lazy_grouping(grouper, expect_index):
3106
3106
3107
3107
3108
3108
@requires_dask
3109
- def test_lazy_grouping_errors ():
3109
+ def test_lazy_grouping_errors () -> None :
3110
3110
import dask .array
3111
3111
3112
3112
data = DataArray (
@@ -3132,15 +3132,15 @@ def test_lazy_grouping_errors():
3132
3132
3133
3133
3134
3134
@requires_dask
3135
- def test_lazy_int_bins_error ():
3135
+ def test_lazy_int_bins_error () -> None :
3136
3136
import dask .array
3137
3137
3138
3138
with pytest .raises (ValueError , match = "Bin edges must be provided" ):
3139
3139
with raise_if_dask_computes ():
3140
3140
_ = BinGrouper (bins = 4 ).factorize (DataArray (dask .array .arange (3 )))
3141
3141
3142
3142
3143
- def test_time_grouping_seasons_specified ():
3143
+ def test_time_grouping_seasons_specified () -> None :
3144
3144
time = xr .date_range ("2001-01-01" , "2002-01-01" , freq = "D" )
3145
3145
ds = xr .Dataset ({"foo" : np .arange (time .size )}, coords = {"time" : ("time" , time )})
3146
3146
labels = ["DJF" , "MAM" , "JJA" , "SON" ]
@@ -3149,7 +3149,36 @@ def test_time_grouping_seasons_specified():
3149
3149
assert_identical (actual , expected .reindex (season = labels ))
3150
3150
3151
3151
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 :
3153
3182
from numpy import nan
3154
3183
3155
3184
ds = xr .Dataset (
@@ -3226,7 +3255,7 @@ def test_shuffle_by(chunks, expected_chunks):
3226
3255
3227
3256
3228
3257
@requires_dask
3229
- def test_groupby_dask_eager_load_warnings ():
3258
+ def test_groupby_dask_eager_load_warnings () -> None :
3230
3259
ds = xr .Dataset (
3231
3260
{"foo" : (("z" ), np .arange (12 ))},
3232
3261
coords = {"x" : ("z" , np .arange (12 )), "y" : ("z" , np .arange (12 ))},
0 commit comments