-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: Fix series clipping NA issue #41141
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
Conversation
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.
Please add tests
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.
pls add a whatsnew note, bug fixes numeric section
pandas/tests/generic/test_series.py
Outdated
@@ -134,3 +134,17 @@ def finalize(self, other, method=None, **kwargs): | |||
# reset | |||
Series._metadata = _metadata | |||
Series.__finalize__ = _finalize # FIXME: use monkeypatch | |||
|
|||
def test_series_clipping_with_na_values(self): |
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.
move to pandas/tests/series/methods/test_clip.py
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.
Done
pandas/tests/generic/test_series.py
Outdated
@@ -134,3 +134,17 @@ def finalize(self, other, method=None, **kwargs): | |||
# reset | |||
Series._metadata = _metadata | |||
Series.__finalize__ = _finalize # FIXME: use monkeypatch | |||
|
|||
def test_series_clipping_with_na_values(self): |
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.
can you parameterize by nullable int & float types (I think we have a fixture for this)
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.
I parameterized the test but I could not find any clear listing of all nullable int and float types.
@@ -40,6 +40,21 @@ def test_clip_types_and_nulls(self): | |||
assert list(isna(s)) == list(isna(lower)) | |||
assert list(isna(s)) == list(isna(upper)) | |||
|
|||
@pytest.mark.parametrize("dtypes", ["Float64", "Int64", "Float32", "Int32"]) |
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 have fixtures for all of these look in pandas/conftest.py
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.
I am not familiar with testing but I think I got it this time. I also expanded the test to cover all nulls as there was a fixture for it already. Thanks for your tips!
Series clipping method could not handle series with NA values. Issue was fixed by first comparing values and only after then converted to numpy array.
The test fail is not related to my changes. E: I re-pushed the changes to see if the check passes this time. At least checks of other PRs are passing ... |
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.
lgtm
thanks @Rasori |
This seemed to cause a performance regression. https://pandas.pydata.org/speed/pandas/index.html#series_methods.Clip.time_clip?python=3.8&Cython=0.29.21&p-n=50&commits=29512dc9ea2b066ab5f4a7cb80c1f8f5becef1c2 |
@TomAugspurger if u wouldn't mind creating a new issue about this perf regression |
Series clipping method could not handle series with NA values.
Issue was fixed by first comparing values and only after then converted
to numpy array. Now the test code provided with the issue ticket provides an expected result.