@@ -1137,6 +1137,11 @@ def get_reindex_type(target):
1137
1137
self .assertEqual (reindexed .levels [0 ].dtype .type , np .int64 )
1138
1138
self .assertEqual (reindexed .levels [1 ].dtype .type , np .float64 )
1139
1139
1140
+ def test_groupby (self ):
1141
+ idx = Index (range (5 ))
1142
+ groups = idx .groupby (np .array ([1 ,1 ,2 ,2 ,2 ]))
1143
+ exp = {1 : [0 , 1 ], 2 : [2 , 3 , 4 ]}
1144
+ tm .assert_dict_equal (groups , exp )
1140
1145
1141
1146
1142
1147
class Numeric (Base ):
@@ -3524,6 +3529,17 @@ def test_reindex_lvl_preserves_type_if_target_is_empty_list_or_array(self):
3524
3529
self .assertEqual (idx .reindex ([], level = 1 )[0 ].levels [1 ].dtype .type ,
3525
3530
np .object_ )
3526
3531
3532
+ def test_groupby (self ):
3533
+ groups = self .index .groupby (np .array ([1 , 1 , 1 , 2 , 2 , 2 ]))
3534
+ labels = self .index .get_values ().tolist ()
3535
+ exp = {1 : labels [:3 ], 2 : labels [3 :]}
3536
+ tm .assert_dict_equal (groups , exp )
3537
+
3538
+ # GH5620
3539
+ groups = self .index .groupby (self .index )
3540
+ exp = dict ((key , [key ]) for key in self .index )
3541
+ tm .assert_dict_equal (groups , exp )
3542
+
3527
3543
3528
3544
def test_get_combined_index ():
3529
3545
from pandas .core .index import _get_combined_index
0 commit comments