From 5468242a64c1115c00da26bc948babab3fcc8166 Mon Sep 17 00:00:00 2001 From: phofl Date: Mon, 9 Nov 2020 20:47:37 +0100 Subject: [PATCH] TST: Add test for missing fillvalue in categorical dtype --- pandas/tests/indexes/categorical/test_reindex.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pandas/tests/indexes/categorical/test_reindex.py b/pandas/tests/indexes/categorical/test_reindex.py index f59ddc42ce4e4..189582ea635d2 100644 --- a/pandas/tests/indexes/categorical/test_reindex.py +++ b/pandas/tests/indexes/categorical/test_reindex.py @@ -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 @@ -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)