-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
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
Changes from all commits
5ef4eba
4f3bcbc
fda8be0
94a738f
5b21ba5
1280b32
01fec55
baeae0c
502f827
42895db
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 |
---|---|---|
|
@@ -202,7 +202,7 @@ 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): | ||
def test_interp_raise_on_only_mixed(self, axis): | ||
df = DataFrame( | ||
{ | ||
"A": [1, 2, np.nan, 4], | ||
|
@@ -212,8 +212,13 @@ def test_interp_raise_on_only_mixed(self): | |
"E": [1, 2, 3, 4], | ||
} | ||
) | ||
with pytest.raises(TypeError): | ||
df.interpolate(axis=1) | ||
msg = ( | ||
"Cannot interpolate with all object-dtype columns " | ||
"in the DataFrame. Try setting at least one " | ||
"column to a numeric dtype." | ||
) | ||
with pytest.raises(TypeError, match=msg): | ||
df.astype("object").interpolate(axis=axis) | ||
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. why is this changed? 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. check the error message here 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. done |
||
|
||
def test_interp_raise_on_all_object_dtype(self): | ||
# GH 22985 | ||
|
@@ -272,7 +277,6 @@ def test_interp_ignore_all_good(self): | |
result = df[["B", "D"]].interpolate(downcast=None) | ||
tm.assert_frame_equal(result, df[["B", "D"]]) | ||
|
||
@pytest.mark.parametrize("axis", [0, 1]) | ||
def test_interp_time_inplace_axis(self, axis): | ||
# GH 9687 | ||
periods = 5 | ||
|
@@ -296,3 +300,17 @@ 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"]) | ||
def test_interp_fillna_methods(self, axis, method): | ||
# GH 12918 | ||
df = DataFrame( | ||
{ | ||
"A": [1.0, 2.0, 3.0, 4.0, np.nan, 5.0], | ||
"B": [2.0, 4.0, 6.0, np.nan, 8.0, 10.0], | ||
"C": [3.0, 6.0, 9.0, np.nan, np.nan, 30.0], | ||
} | ||
) | ||
expected = df.fillna(axis=axis, method=method) | ||
result = df.interpolate(method=method, axis=axis) | ||
tm.assert_frame_equal(result, expected) |
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