Skip to content

Commit e605559

Browse files
committed
add test for df where with category dtype
1 parent 0de9955 commit e605559

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

pandas/tests/frame/test_dtypes.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -815,6 +815,19 @@ def test_astype_extension_dtypes_duplicate_col(self, dtype):
815815
expected = concat([a1.astype(dtype), a2.astype(dtype)], axis=1)
816816
tm.assert_frame_equal(result, expected)
817817

818+
def test_df_where_with_category(self):
819+
# GH 16979
820+
df = DataFrame(np.arange(2 * 3).reshape(2, 3), columns=list("ABC"))
821+
mask = np.array([[True, False, True], [False, True, True]])
822+
# change type to category
823+
df.A = df.A.astype("category")
824+
df.B = df.B.astype("category")
825+
df.C = df.C.astype("category")
826+
827+
expected = df.A.where(mask[:, 0])
828+
result = df.A.where(mask[:, 0], other=None)
829+
tm.assert_series_equal(result, expected)
830+
818831
@pytest.mark.parametrize(
819832
"dtype", [{100: "float64", 200: "uint64"}, "category", "float64"]
820833
)

0 commit comments

Comments
 (0)