Skip to content

TST: Asserts all types are caterogical in function fillna with correct error message #27933

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 5 commits into from
Aug 16, 2019
Merged
Show file tree
Hide file tree
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
1 change: 0 additions & 1 deletion doc/source/whatsnew/v0.25.1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ Bug fixes
Categorical
^^^^^^^^^^^

-
-
-

Expand Down
1 change: 1 addition & 0 deletions doc/source/whatsnew/v1.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ Bug fixes
Categorical
^^^^^^^^^^^

- Added test to assert the :func:`fillna` raises the correct ValueError message when the value isn't a value from categories (:issue:`13628`)
-
-

Expand Down
6 changes: 4 additions & 2 deletions pandas/tests/arrays/categorical/test_missing.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from pandas.core.dtypes.dtypes import CategoricalDtype

from pandas import Categorical, Index, isna
from pandas import Categorical, Index, Series, isna
import pandas.util.testing as tm


Expand Down Expand Up @@ -59,11 +59,13 @@ def test_set_item_nan(self):
),
(dict(), "Must specify a fill 'value' or 'method'."),
(dict(method="bad"), "Invalid fill method. Expecting .* bad"),
(dict(value=Series([1, 2, 3, 4, "a"])), "fill value must be in categories"),
],
)
def test_fillna_raises(self, fillna_kwargs, msg):
# https://github.com/pandas-dev/pandas/issues/19682
cat = Categorical([1, 2, 3])
# https://github.com/pandas-dev/pandas/issues/13628
cat = Categorical([1, 2, 3, None, None])

with pytest.raises(ValueError, match=msg):
cat.fillna(**fillna_kwargs)
Expand Down