Skip to content

Commit 01cf2f2

Browse files
authored
Tests for where() with categorical (#37182)
1 parent 055651b commit 01cf2f2

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

pandas/tests/series/indexing/test_where.py

+12
Original file line numberDiff line numberDiff line change
@@ -452,3 +452,15 @@ def test_where_empty_series_and_empty_cond_having_non_bool_dtypes():
452452
ser = Series([], dtype=float)
453453
result = ser.where([])
454454
tm.assert_series_equal(result, ser)
455+
456+
457+
@pytest.mark.parametrize("klass", [Series, pd.DataFrame])
458+
def test_where_categorical(klass):
459+
# https://github.com/pandas-dev/pandas/issues/18888
460+
exp = klass(
461+
pd.Categorical(["A", "A", "B", "B", np.nan], categories=["A", "B", "C"]),
462+
dtype="category",
463+
)
464+
df = klass(["A", "A", "B", "B", "C"], dtype="category")
465+
res = df.where(df != "C")
466+
tm.assert_equal(exp, res)

0 commit comments

Comments
 (0)