Skip to content

Commit 802f670

Browse files
LiuSeekerjreback
authored andcommitted
TST: Asserts all types are caterogical in function fillna with correct error message (#27933)
* Fixes issue #13628 * Fixes issue #13628 fix * isort Fixes #13628 * move to 1.0
1 parent d03beab commit 802f670

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed

doc/source/whatsnew/v0.25.1.rst

-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ Categorical
2727

2828
- Bug in :meth:`Categorical.fillna` would replace all values, not just those that are ``NaN`` (:issue:`26215`)
2929
-
30-
-
3130

3231
Datetimelike
3332
^^^^^^^^^^^^

doc/source/whatsnew/v1.0.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ Bug fixes
8787
Categorical
8888
^^^^^^^^^^^
8989

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

pandas/tests/arrays/categorical/test_missing.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from pandas.core.dtypes.dtypes import CategoricalDtype
77

8-
from pandas import Categorical, Index, isna
8+
from pandas import Categorical, Index, Series, isna
99
import pandas.util.testing as tm
1010

1111

@@ -59,11 +59,13 @@ def test_set_item_nan(self):
5959
),
6060
(dict(), "Must specify a fill 'value' or 'method'."),
6161
(dict(method="bad"), "Invalid fill method. Expecting .* bad"),
62+
(dict(value=Series([1, 2, 3, 4, "a"])), "fill value must be in categories"),
6263
],
6364
)
6465
def test_fillna_raises(self, fillna_kwargs, msg):
6566
# https://github.com/pandas-dev/pandas/issues/19682
66-
cat = Categorical([1, 2, 3])
67+
# https://github.com/pandas-dev/pandas/issues/13628
68+
cat = Categorical([1, 2, 3, None, None])
6769

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

0 commit comments

Comments
 (0)