-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: na parameter for str.startswith and str.endswith not propagating for Series with categorical dtype #36249
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 2 commits
e9a418d
1a5cf4f
2f90e6b
54e486e
70b6e3c
44d386e
5e3be5a
d8e5bb7
1467a0a
9d0070c
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 |
---|---|---|
|
@@ -838,8 +838,12 @@ def test_contains_for_object_category(self): | |
expected = Series([True, False, False, True, False]) | ||
tm.assert_series_equal(result, expected) | ||
|
||
def test_startswith(self): | ||
values = Series(["om", np.nan, "foo_nom", "nom", "bar_foo", np.nan, "foo"]) | ||
# add category dtype parametrizations for GH-36241 | ||
@pytest.mark.parametrize("dtype", [None, "category"]) | ||
def test_startswith(self, dtype): | ||
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 think we would want to parameterize over different fill values to test the behavior from the OP 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. parameterized over True, False question here: for string Series with dtype = object, passing strings into the In [49]: pd.Series(['a', np.nan, 'b']).str.startswith('a', na='c')
Out[49]:
0 True
1 c
2 False
dtype: object
In [50]: pd.Series(['a', np.nan, 'b'], dtype='string').str.startswith('a', na='c')
Out[50]:
0 True
1 True
2 False
dtype: boolean
In [53]: pd.Series(['a', np.nan, 'b'], dtype='category').str.startswith('a', na='c')
Out[53]:
0 True
1 c
2 False
dtype: object edits: copying the wrong cells!! |
||
values = Series( | ||
["om", np.nan, "foo_nom", "nom", "bar_foo", np.nan, "foo"], dtype=dtype | ||
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. also pls tests with pd.NA as well (you can parameterize over the null value as well |
||
) | ||
|
||
result = values.str.startswith("foo") | ||
exp = Series([False, np.nan, True, False, False, np.nan, True]) | ||
|
@@ -867,8 +871,12 @@ def test_startswith(self): | |
) | ||
tm.assert_series_equal(rs, xp) | ||
|
||
def test_endswith(self): | ||
values = Series(["om", np.nan, "foo_nom", "nom", "bar_foo", np.nan, "foo"]) | ||
# add category dtype parametrizations for GH-36241 | ||
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. add inside the test |
||
@pytest.mark.parametrize("dtype", [None, "category"]) | ||
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. same as above |
||
def test_endswith(self, dtype): | ||
values = Series( | ||
["om", np.nan, "foo_nom", "nom", "bar_foo", np.nan, "foo"], dtype=dtype | ||
) | ||
|
||
result = values.str.endswith("foo") | ||
exp = Series([False, np.nan, False, False, True, np.nan, True]) | ||
|
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.
we want to parameterize over 'string' dtype as well rigth?
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.
string arrays are already tested here
https://github.com/pandas-dev/pandas/blob/1.1.x/pandas/tests/test_strings.py#L3530-L3531
parametrizing over string dtype and na=True/False was making it a bit tricky as these methods return boolean series causing a dtype mismatch (boolean vs object)
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.
@jreback tried to do that changing the referenced tests slightly with
https://github.com/pandas-dev/pandas/pull/36249/files#diff-683f8dacd08abda4913680fafe3a4ea7R3573-R3576 , https://github.com/pandas-dev/pandas/pull/36249/files#diff-683f8dacd08abda4913680fafe3a4ea7R32-R33 and https://github.com/pandas-dev/pandas/pull/36249/files#diff-683f8dacd08abda4913680fafe3a4ea7R63-R64