@@ -994,6 +994,22 @@ def test_rename_categories_dict(self):
994
994
inplace = True )
995
995
assert res is None
996
996
tm .assert_index_equal (cat .categories , expected )
997
+ # Test for dicts of smaller length
998
+ cat = pd .Categorical (['a' , 'b' , 'c' , 'd' ])
999
+ res = cat .rename_categories ({'a' : 1 , 'c' : 3 })
1000
+ expected = Index ([1 , 'b' , 3 , 'd' ])
1001
+ tm .assert_index_equal (res .categories , expected )
1002
+ # Test for dicts with bigger length
1003
+ cat = pd .Categorical (['a' , 'b' , 'c' , 'd' ])
1004
+ res = cat .rename_categories ({'a' : 1 , 'b' : 2 , 'c' : 3 ,
1005
+ 'd' : 4 , 'e' : 5 , 'f' : 6 })
1006
+ expected = Index ([1 , 2 , 3 , 4 ])
1007
+ tm .assert_index_equal (res .categories , expected )
1008
+ # Test for dicts with no items from old categories
1009
+ cat = pd .Categorical (['a' , 'b' , 'c' , 'd' ])
1010
+ res = cat .rename_categories ({'f' : 1 , 'g' : 3 })
1011
+ expected = Index (['a' , 'b' , 'c' , 'd' ])
1012
+ tm .assert_index_equal (res .categories , expected )
997
1013
998
1014
@pytest .mark .parametrize ('codes, old, new, expected' , [
999
1015
([0 , 1 ], ['a' , 'b' ], ['a' , 'b' ], [0 , 1 ]),
0 commit comments