Skip to content

Commit 0eb33fb

Browse files
committed
Add more testing to renaming categories with dicts
1 parent 022aa9f commit 0eb33fb

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

pandas/tests/test_categorical.py

+16
Original file line numberDiff line numberDiff line change
@@ -994,6 +994,22 @@ def test_rename_categories_dict(self):
994994
inplace=True)
995995
assert res is None
996996
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)
9971013

9981014
@pytest.mark.parametrize('codes, old, new, expected', [
9991015
([0, 1], ['a', 'b'], ['a', 'b'], [0, 1]),

0 commit comments

Comments
 (0)