-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
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
ENH: Add limit_area to ffill/bfill #56531
Changes from all commits
84b0098
caa3a3e
0fa955f
77da65a
5d42755
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 |
---|---|---|
|
@@ -857,3 +857,100 @@ def test_pad_backfill_deprecated(func): | |
df = DataFrame({"a": [1, 2, 3]}) | ||
with tm.assert_produces_warning(FutureWarning): | ||
getattr(df, func)() | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"data, expected_data, method, kwargs", | ||
( | ||
pytest.param( | ||
[np.nan, np.nan, 3, np.nan, np.nan, np.nan, 7, np.nan, np.nan], | ||
[np.nan, np.nan, 3.0, 3.0, 3.0, 3.0, 7.0, np.nan, np.nan], | ||
"ffill", | ||
{"limit_area": "inside"}, | ||
marks=pytest.mark.xfail( | ||
reason="GH#41813 - limit_area applied to the wrong axis" | ||
), | ||
), | ||
pytest.param( | ||
[np.nan, np.nan, 3, np.nan, np.nan, np.nan, 7, np.nan, np.nan], | ||
[np.nan, np.nan, 3.0, 3.0, np.nan, np.nan, 7.0, np.nan, np.nan], | ||
"ffill", | ||
{"limit_area": "inside", "limit": 1}, | ||
marks=pytest.mark.xfail( | ||
reason="GH#41813 - limit_area applied to the wrong axis" | ||
), | ||
), | ||
pytest.param( | ||
[np.nan, np.nan, 3, np.nan, np.nan, np.nan, 7, np.nan, np.nan], | ||
[np.nan, np.nan, 3.0, np.nan, np.nan, np.nan, 7.0, 7.0, 7.0], | ||
"ffill", | ||
{"limit_area": "outside"}, | ||
marks=pytest.mark.xfail( | ||
reason="GH#41813 - limit_area applied to the wrong axis" | ||
), | ||
), | ||
pytest.param( | ||
[np.nan, np.nan, 3, np.nan, np.nan, np.nan, 7, np.nan, np.nan], | ||
[np.nan, np.nan, 3.0, np.nan, np.nan, np.nan, 7.0, 7.0, np.nan], | ||
"ffill", | ||
{"limit_area": "outside", "limit": 1}, | ||
marks=pytest.mark.xfail( | ||
reason="GH#41813 - limit_area applied to the wrong axis" | ||
), | ||
), | ||
( | ||
[np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan], | ||
[np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan], | ||
"ffill", | ||
{"limit_area": "outside", "limit": 1}, | ||
), | ||
( | ||
range(5), | ||
range(5), | ||
"ffill", | ||
{"limit_area": "outside", "limit": 1}, | ||
), | ||
pytest.param( | ||
[np.nan, np.nan, 3, np.nan, np.nan, np.nan, 7, np.nan, np.nan], | ||
[np.nan, np.nan, 3.0, 7.0, 7.0, 7.0, 7.0, np.nan, np.nan], | ||
"bfill", | ||
{"limit_area": "inside"}, | ||
marks=pytest.mark.xfail( | ||
reason="GH#41813 - limit_area applied to the wrong axis" | ||
), | ||
), | ||
pytest.param( | ||
[np.nan, np.nan, 3, np.nan, np.nan, np.nan, 7, np.nan, np.nan], | ||
[np.nan, np.nan, 3.0, np.nan, np.nan, 7.0, 7.0, np.nan, np.nan], | ||
"bfill", | ||
{"limit_area": "inside", "limit": 1}, | ||
marks=pytest.mark.xfail( | ||
reason="GH#41813 - limit_area applied to the wrong axis" | ||
), | ||
), | ||
pytest.param( | ||
[np.nan, np.nan, 3, np.nan, np.nan, np.nan, 7, np.nan, np.nan], | ||
[3.0, 3.0, 3.0, np.nan, np.nan, np.nan, 7.0, np.nan, np.nan], | ||
"bfill", | ||
{"limit_area": "outside"}, | ||
marks=pytest.mark.xfail( | ||
reason="GH#41813 - limit_area applied to the wrong axis" | ||
), | ||
), | ||
pytest.param( | ||
[np.nan, np.nan, 3, np.nan, np.nan, np.nan, 7, np.nan, np.nan], | ||
[np.nan, 3.0, 3.0, np.nan, np.nan, np.nan, 7.0, np.nan, np.nan], | ||
"bfill", | ||
{"limit_area": "outside", "limit": 1}, | ||
marks=pytest.mark.xfail( | ||
reason="GH#41813 - limit_area applied to the wrong axis" | ||
), | ||
), | ||
), | ||
) | ||
def test_ffill_bfill_limit_area(data, expected_data, method, kwargs): | ||
# GH#56492 | ||
df = DataFrame(data) | ||
expected = DataFrame(expected_data) | ||
result = getattr(df, method)(**kwargs) | ||
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. Looks like the tests all use numpy dtypes; would this work with EAs? id expect the limit_area kwd to be added to EA._pad_of_backfill but dont see it there 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. Thanks - I missed this, interpolate currently ignores limit_area with ffill/bfill and EAs, so this will too. The implementation appears to be straightforward enough to add. I think I should be able to do this in the next week, but do we want to revert this PR for the RC? 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. im not going to lose sleep either way 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 would say it's fine to just add this after the RC |
||
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.
im a bit late here, but these tests look really similar to the series ones. is there a viable way to share them?
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.
Yes - but where would they go? Just all in frame/methods?
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.
usually we put them in the frame/methods/test_foo.py file and parametrize over frame_or_series