-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
PERF: GH2003 Series.isin for categorical dtypes #20522
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
Changes from all commits
19ac11a
54021b9
2514b45
80f687a
d6c3953
33e3b07
ceffccd
3247dce
2b7b1c4
4478a49
64fef49
b25da12
9f8e790
60ac658
50aca26
713712e
18c827d
993afd8
a2b70ee
fa7f0f1
7b680cd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3567,7 +3567,7 @@ def isin(self, values): | |
5 False | ||
Name: animal, dtype: bool | ||
""" | ||
result = algorithms.isin(com._values_from_object(self), values) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes let's try to do this, @Ma3aXaKa can you make this change |
||
result = algorithms.isin(self, values) | ||
return self._constructor(result, index=self.index).__finalize__(self) | ||
|
||
def between(self, left, right, inclusive=True): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,3 +47,25 @@ def test_factorized_sort_ordered(): | |
|
||
tm.assert_numpy_array_equal(labels, expected_labels) | ||
tm.assert_categorical_equal(uniques, expected_uniques) | ||
|
||
|
||
def test_isin_cats(): | ||
# GH2003 | ||
cat = pd.Categorical(["a", "b", np.nan]) | ||
|
||
result = cat.isin(["a", np.nan]) | ||
expected = np.array([True, False, True], dtype=bool) | ||
tm.assert_numpy_array_equal(expected, result) | ||
|
||
result = cat.isin(["a", "c"]) | ||
expected = np.array([True, False, False], dtype=bool) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. there are a couple of tests in pandas/tests/test_algos.py that test cats for isin, can you move here |
||
tm.assert_numpy_array_equal(expected, result) | ||
|
||
|
||
@pytest.mark.parametrize("empty", [[], pd.Series(), np.array([])]) | ||
def test_isin_empty(empty): | ||
s = pd.Categorical(["a", "b"]) | ||
expected = np.array([False, False], dtype=bool) | ||
|
||
result = s.isin(empty) | ||
tm.assert_numpy_array_equal(expected, result) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if u change this to is_extension_type does everything still work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, can you add a note: TODO(extension) here