Skip to content

TST: Add test for category equalness on applies (#21239) #35125

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 1 commit into from
Jul 6, 2020
Merged
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
12 changes: 12 additions & 0 deletions pandas/tests/frame/test_apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -793,6 +793,18 @@ def test_apply_with_byte_string(self):
result = df.apply(lambda x: x.astype("object"))
tm.assert_frame_equal(result, expected)

@pytest.mark.parametrize("val", ["asd", 12, None, np.NaN])
def test_apply_category_equalness(self, val):
# Check if categorical comparisons on apply, GH 21239
df_values = ["asd", None, 12, "asd", "cde", np.NaN]
df = pd.DataFrame({"a": df_values}, dtype="category")

result = df.a.apply(lambda x: x == val)
expected = pd.Series(
[np.NaN if pd.isnull(x) else x == val for x in df_values], name="a"
)
tm.assert_series_equal(result, expected)


class TestInferOutputShape:
# the user has supplied an opaque UDF where
Expand Down