@@ -202,4 +202,44 @@ def test_da_groupby_assign_coords():
202
202
assert_identical (expected , actual2 )
203
203
204
204
205
+ repr_da = xr .DataArray (
206
+ np .random .randn (10 , 20 , 6 , 24 ),
207
+ dims = ["x" , "y" , "z" , "t" ],
208
+ coords = {
209
+ "z" : ["a" , "b" , "c" , "a" , "b" , "c" ],
210
+ "x" : [1 , 1 , 1 , 2 , 2 , 3 , 4 , 5 , 3 , 4 ],
211
+ "t" : pd .date_range ("2001-01-01" , freq = "M" , periods = 24 ),
212
+ "month" : ("t" , list (range (1 , 13 )) * 2 ),
213
+ },
214
+ )
215
+
216
+
217
+ @pytest .mark .parametrize ("dim" , ["x" , "y" , "z" , "month" ])
218
+ @pytest .mark .parametrize ("obj" , [repr_da , repr_da .to_dataset (name = "a" )])
219
+ def test_groupby_repr (obj , dim ):
220
+ actual = repr (obj .groupby (dim ))
221
+ expected = "%sGroupBy" % obj .__class__ .__name__
222
+ expected += ", grouped over %r " % dim
223
+ expected += "\n %r groups with labels " % (len (np .unique (obj [dim ])))
224
+ if dim == "x" :
225
+ expected += "1, 2, 3, 4, 5"
226
+ elif dim == "y" :
227
+ expected += "0, 1, 2, 3, 4, 5, ..., 15, 16, 17, 18, 19"
228
+ elif dim == "z" :
229
+ expected += "'a', 'b', 'c'"
230
+ elif dim == "month" :
231
+ expected += "1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12"
232
+ assert actual == expected
233
+
234
+
235
+ @pytest .mark .parametrize ("obj" , [repr_da , repr_da .to_dataset (name = "a" )])
236
+ def test_groupby_repr_datetime (obj ):
237
+ actual = repr (obj .groupby ("t.month" ))
238
+ expected = "%sGroupBy" % obj .__class__ .__name__
239
+ expected += ", grouped over 'month' "
240
+ expected += "\n %r groups with labels " % (len (np .unique (obj .t .dt .month )))
241
+ expected += "1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12"
242
+ assert actual == expected
243
+
244
+
205
245
# TODO: move other groupby tests from test_dataset and test_dataarray over here
0 commit comments