Skip to content

Commit 9e44618

Browse files
authored
TST: Add test for category equalness on applies (pandas-dev#21239) (pandas-dev#35125)
1 parent efcf4b4 commit 9e44618

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

pandas/tests/frame/test_apply.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -793,6 +793,18 @@ def test_apply_with_byte_string(self):
793793
result = df.apply(lambda x: x.astype("object"))
794794
tm.assert_frame_equal(result, expected)
795795

796+
@pytest.mark.parametrize("val", ["asd", 12, None, np.NaN])
797+
def test_apply_category_equalness(self, val):
798+
# Check if categorical comparisons on apply, GH 21239
799+
df_values = ["asd", None, 12, "asd", "cde", np.NaN]
800+
df = pd.DataFrame({"a": df_values}, dtype="category")
801+
802+
result = df.a.apply(lambda x: x == val)
803+
expected = pd.Series(
804+
[np.NaN if pd.isnull(x) else x == val for x in df_values], name="a"
805+
)
806+
tm.assert_series_equal(result, expected)
807+
796808

797809
class TestInferOutputShape:
798810
# the user has supplied an opaque UDF where

0 commit comments

Comments
 (0)