@@ -1285,14 +1285,35 @@ def test_groupby_list_infer_array_like(self):
1285
1285
result = df .groupby (['foo' , 'bar' ]).mean ()
1286
1286
expected = df .groupby ([df ['foo' ], df ['bar' ]]).mean ()[['val' ]]
1287
1287
1288
-
1289
- class TestPanelGroupBy (unittest .TestCase ):
1290
-
1291
- def setUp (self ):
1288
+ def test_dictify (self ):
1289
+ dict (iter (self .df .groupby ('A' )))
1290
+ dict (iter (self .df .groupby (['A' , 'B' ])))
1291
+ dict (iter (self .df ['C' ].groupby (self .df ['A' ])))
1292
+ dict (iter (self .df ['C' ].groupby ([self .df ['A' ], self .df ['B' ]])))
1293
+ dict (iter (self .df .groupby ('A' )['C' ]))
1294
+ dict (iter (self .df .groupby (['A' , 'B' ])['C' ]))
1295
+
1296
+ def test_sparse_friendly (self ):
1297
+ sdf = self .df [['C' , 'D' ]].to_sparse ()
1298
+ panel = tm .makePanel ()
1299
+ tm .add_nans (panel )
1300
+
1301
+ def _check_work (gp ):
1302
+ gp .mean ()
1303
+ gp .agg (np .mean )
1304
+ dict (iter (gp ))
1305
+
1306
+ # it works!
1307
+ _check_work (sdf .groupby (lambda x : x // 2 ))
1308
+ _check_work (sdf ['C' ].groupby (lambda x : x // 2 ))
1309
+ _check_work (sdf .groupby (self .df ['A' ]))
1310
+
1311
+ # do this someday
1312
+ # _check_work(panel.groupby(lambda x: x.month, axis=1))
1313
+
1314
+ def test_panel_groupby (self ):
1292
1315
self .panel = tm .makePanel ()
1293
1316
tm .add_nans (self .panel )
1294
-
1295
- def test_groupby (self ):
1296
1317
grouped = self .panel .groupby ({'ItemA' : 0 , 'ItemB' : 0 , 'ItemC' : 1 },
1297
1318
axis = 'items' )
1298
1319
agged = grouped .agg (np .mean )
0 commit comments