@@ -1137,6 +1137,11 @@ def get_reindex_type(target):
11371137 self .assertEqual (reindexed .levels [0 ].dtype .type , np .int64 )
11381138 self .assertEqual (reindexed .levels [1 ].dtype .type , np .float64 )
11391139
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 )
11401145
11411146
11421147class Numeric (Base ):
@@ -3524,6 +3529,17 @@ def test_reindex_lvl_preserves_type_if_target_is_empty_list_or_array(self):
35243529 self .assertEqual (idx .reindex ([], level = 1 )[0 ].levels [1 ].dtype .type ,
35253530 np .object_ )
35263531
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+
35273543
35283544def test_get_combined_index ():
35293545 from pandas .core .index import _get_combined_index
0 commit comments