Skip to content

TST: Add test for missing fillvalue in categorical dtype #37720

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 9, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion pandas/tests/indexes/categorical/test_reindex.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import numpy as np
import pytest

from pandas import Categorical, CategoricalIndex, Index
from pandas import Categorical, CategoricalIndex, Index, Series
import pandas._testing as tm


Expand Down Expand Up @@ -51,3 +52,10 @@ def test_reindex_empty_index(self):
res, indexer = c.reindex(["a", "b"])
tm.assert_index_equal(res, Index(["a", "b"]), exact=True)
tm.assert_numpy_array_equal(indexer, np.array([-1, -1], dtype=np.intp))

def test_reindex_missing_category(self):
# GH: 18185
ser = Series([1, 2, 3, 1], dtype="category")
msg = "'fill_value=-1' is not present in this Categorical's categories"
with pytest.raises(ValueError, match=msg):
ser.reindex([1, 2, 3, 4, 5], fill_value=-1)