-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
fix bfill, ffill and pad when calling with df.interpolate with column… #33959
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.
Thanks @CloseChoice for the PR.
not sure we should be adding tests for incorrect/undoumented behaviour. see #33956 (comment)
xref #12918 maybe the tests could test for equality with either DataFrame.ffill or DataFrame.fillna(method='ffill) and update the DataFrame.interpolate docstring, see #12918 (comment) and #12918 (comment) |
can you merge master |
I went to the interpolate function back and forth and I come to the conclusion that we totally should fix this first. When we want to ensure that The whole EDIT: |
Hello @CloseChoice! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found: There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻 Comment last updated at 2020-05-29 16:26:02 UTC |
consistens with previous version, add TODO
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.
Thanks @CloseChoice for the updates, is it feasible for the fixes for #12918 and #29146 be split off into a pre-cursor PR. smaller PRs with more atomic changes are easier to review/quicker to merge. also needs a whatsnew.
@@ -296,3 +297,45 @@ def test_interp_string_axis(self, axis_name, axis_number): | |||
result = df.interpolate(method="linear", axis=axis_name) | |||
expected = df.interpolate(method="linear", axis=axis_number) | |||
tm.assert_frame_equal(result, expected) | |||
|
|||
@pytest.mark.parametrize("axis", [0, 1]) | |||
def test_interp_ffill(self, axis): |
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 parameterise these tests @pytest.mark.parametrize("method", ["ffill", "bfill", "pad"])
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
"Only `method=linear` interpolation is supported on MultiIndexes." | ||
) | ||
|
||
if method in ["backfill", "bfill", "pad", "ffill"]: |
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 add a comment here that for these methods, limit_direction and limit_area are being ignored and include a link to #26796
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
Thanks for your review. Actually fixing #12918 and #29146 has the side effect of fixing #33956, since the |
pandas/core/generic.py
Outdated
|
||
# todo: change interpolation so that no transposing is necessary |
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.
TODO
@@ -202,7 +202,8 @@ def test_interp_leading_nans(self, check_scipy): | |||
result = df.interpolate(method="polynomial", order=1) | |||
tm.assert_frame_equal(result, expected) | |||
|
|||
def test_interp_raise_on_only_mixed(self): | |||
@pytest.mark.parametrize("axis", [0, 1]) |
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.
use the axis fixture (e.g. just pass axis as the arg)
@@ -213,7 +214,7 @@ def test_interp_raise_on_only_mixed(self): | |||
} | |||
) | |||
with pytest.raises(TypeError): | |||
df.interpolate(axis=1) | |||
df.astype("object").interpolate(axis=axis) |
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.
why is this changed?
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.
check the error message here
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
@@ -296,3 +297,18 @@ def test_interp_string_axis(self, axis_name, axis_number): | |||
result = df.interpolate(method="linear", axis=axis_name) | |||
expected = df.interpolate(method="linear", axis=axis_number) | |||
tm.assert_frame_equal(result, expected) | |||
|
|||
@pytest.mark.parametrize("method", ["ffill", "bfill", "pad"]) | |||
@pytest.mark.parametrize("axis", [0, 1]) |
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.
axis fixture
pandas/core/generic.py
Outdated
) | ||
|
||
# for the methods backfill, bfill, pad, ffill limit_direction and limit_area | ||
# are being ignored, see #26796 for more information |
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.
list as gh-26796
…nterpolate and check message
thanks @CloseChoice very nice |
… dtype string (#33956)
black pandas
git diff upstream/master -u -- "*.py" | flake8 --diff