@@ -1152,21 +1152,33 @@ def test_groupby_count(self):
1152
1152
expected = DataArray ([1 , 1 , 2 ], coords = [("cat" , ["a" , "b" , "c" ])])
1153
1153
assert_identical (actual , expected )
1154
1154
1155
- @pytest .mark .skip ("needs to be fixed for shortcut=False, keep_attrs=False" )
1156
- def test_groupby_reduce_attrs (self ):
1155
+ @pytest .mark .parametrize ("shortcut" , [True , False ])
1156
+ @pytest .mark .parametrize ("keep_attrs" , [None , True , False ])
1157
+ def test_groupby_reduce_keep_attrs (self , shortcut , keep_attrs ):
1158
+ array = self .da
1159
+ array .attrs ["foo" ] = "bar"
1160
+
1161
+ actual = array .groupby ("abc" ).reduce (
1162
+ np .mean , keep_attrs = keep_attrs , shortcut = shortcut
1163
+ )
1164
+ with xr .set_options (use_flox = False ):
1165
+ expected = array .groupby ("abc" ).mean (keep_attrs = keep_attrs )
1166
+ assert_identical (expected , actual )
1167
+
1168
+ @pytest .mark .parametrize ("keep_attrs" , [None , True , False ])
1169
+ def test_groupby_keep_attrs (self , keep_attrs ):
1157
1170
array = self .da
1158
1171
array .attrs ["foo" ] = "bar"
1159
1172
1160
- for shortcut in [True , False ]:
1161
- for keep_attrs in [True , False ]:
1162
- print (f"shortcut={ shortcut } , keep_attrs={ keep_attrs } " )
1163
- actual = array .groupby ("abc" ).reduce (
1164
- np .mean , keep_attrs = keep_attrs , shortcut = shortcut
1165
- )
1166
- expected = array .groupby ("abc" ).mean ()
1167
- if keep_attrs :
1168
- expected .attrs ["foo" ] = "bar"
1169
- assert_identical (expected , actual )
1173
+ with xr .set_options (use_flox = False ):
1174
+ expected = array .groupby ("abc" ).mean (keep_attrs = keep_attrs )
1175
+ with xr .set_options (use_flox = True ):
1176
+ actual = array .groupby ("abc" ).mean (keep_attrs = keep_attrs )
1177
+
1178
+ # values are tested elsewhere, here we jsut check data
1179
+ # TODO: add check_attrs kwarg to assert_allclose
1180
+ actual .data = expected .data
1181
+ assert_identical (expected , actual )
1170
1182
1171
1183
def test_groupby_map_center (self ):
1172
1184
def center (x ):
0 commit comments