@@ -1152,21 +1152,33 @@ def test_groupby_count(self):
11521152 expected = DataArray ([1 , 1 , 2 ], coords = [("cat" , ["a" , "b" , "c" ])])
11531153 assert_identical (actual , expected )
11541154
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 ):
11571170 array = self .da
11581171 array .attrs ["foo" ] = "bar"
11591172
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 )
11701182
11711183 def test_groupby_map_center (self ):
11721184 def center (x ):
0 commit comments