-
-
Notifications
You must be signed in to change notification settings - Fork 19.4k
ENH: Deprecate non-keyword arguments for Resampler.interpolate #41699
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: Deprecate non-keyword arguments for Resampler.interpolate #41699
Conversation
|
Hello @Anupam-USP! 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 2021-06-04 16:15:25 UTC |
MarcoGorelli
left a comment
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'll review later, but note that this should be Resampler.interpolate, not DataFrame.interpolate - example usage
I have tried but this pre-commit test is not passing by any means. What should I do for passing it? |
| def test_interpolate_posargs_deprecation(): | ||
|
|
||
| s = pd.Series([0.0, 1.0, np.nan, 3.0]) | ||
|
|
||
| msg = ( | ||
| r"In a future version of pandas all arguments of DataFrame\.interpolate " | ||
| r"except for the argument 'method' will be keyword-only" | ||
| ) | ||
|
|
||
| with tm.assert_produces_warning(FutureWarning, match=msg): | ||
| result = s.interpolate() | ||
|
|
||
| expected = pd.Series([0.0, 1.0, 2.0, 3.0]) |
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.
there needs to be resample somewhere in here, and the index should be datetimes, see the example in this question https://stackoverflow.com/q/47148446/4451315 and the other tests in this file
see https://pandas.pydata.org/pandas-docs/stable/development/contributing.html#pre-commit |
MarcoGorelli
left a comment
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.
Getting there 💪
Just a few comments - also, could you add a test where you call resample on a Series?
| data = StringIO( | ||
| """\ | ||
| Values | ||
| 1992-08-27 07:46:48,1 | ||
| 1992-08-27 07:46:59,4""" | ||
| ) | ||
| s = pd.read_csv(data, squeeze=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.
can you construct this directly? something like
data = DataFrame({'ds': ['1992-08-27 07:46:48, '1992-08-27 07:46:59'], 'y': [1, 4]})| data_exp = StringIO( | ||
| """\ | ||
| Values | ||
| 1992-08-27 07:46:48,1.0 | ||
| 1992-08-27 07:46:51,1.0 | ||
| 1992-08-27 07:46:54,1.0 | ||
| 1992-08-27 07:46:57,1.0""" | ||
| ) | ||
|
|
||
| expected = pd.read_csv(data_exp, squeeze=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.
likewise, construct this directly
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.
Okay, will do it in some time!
|
I always fail some cases, no matter what I do. Pasting the check's error is also not giving satisfactory results. What should I do to pass them all? |
| msg = ( | ||
| r"In a future version of pandas all arguments of DataFrame\.interpolate " | ||
| r"except for the argument 'method' will be keyword-only" | ||
| ) |
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.
Does this test pass? The message doesn't seem right, and I"d expect it to be different for the Series case
Have you run
pytest pandas/tests/resample/test_deprecated.py
locally?
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.
It is giving me following error AssertionError: Did not see expected warning of class 'FutureWarning'
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.
OK, so that needs fixing first :) I suggest you remove the with tm.assert_produces_warning, dedent the following line, run the test, check what error message you get, and use that
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 that, got new issues due to resample("3s"), trying to resolve it. I think I have to create expected in another way.
| expected = Series( | ||
| df.iloc[:, 1].values.reshape(-1), index=pd.to_datetime(df.iloc[:, 0].values) | ||
| ) |
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.
construct expected explicitly, don't put logic in tests
| with tm.assert_produces_warning(FutureWarning, match=msg): | ||
| result = s.resample("3s").interpolate("linear") |
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.
need to construct expected and check that result matches it, tm.assert_series_equal
| df = DataFrame({"ds": ["1992-08-27 07:46:48", "1992-08-27 07:46:59"], "y": [1, 4]}) | ||
| s = Series( | ||
| df.iloc[:, 1].values.reshape(-1), index=pd.to_datetime(df.iloc[:, 0].values) | ||
| ) |
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.
Is there a simpler way to create s?
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 think it is needed to give this logic for s, otherwise it is taking the indexes making it not operable
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 do something like
idx = pd.to_datetime(["1992-08-27 07:46:48", "1992-08-27 07:46:59"])
df = DataFrame({'y': [1, 4]}, index=idx)
ser = Series([1, 4], index=idx)
| msg = ( | ||
| r"In a future version of pandas all arguments of DataFrame\.interpolate " | ||
| r"except for the argument 'method' will be keyword-only" | ||
| ) |
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.
OK, so that needs fixing first :) I suggest you remove the with tm.assert_produces_warning, dedent the following line, run the test, check what error message you get, and use that
| df.iloc[:, 1].values.reshape(-1), index=pd.to_datetime(df.iloc[:, 0].values) | ||
| ) | ||
|
|
||
| result = s.resample("3s").interpolate("linear") |
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.
Once you've got the warning message, you need to put the
with tm.assert_produces_warning
back
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.
But with that it is not able to pass the testcase
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.
then you need to fix the code so it passes the testcase 😄
|
@Anupam-USP if you can rebase & update |
|
I am not able to get rid of this issue |
What happens if you remove the |
Do they still pass if you also change to ? If you want, let's continue this discussion on gitter https://gitter.im/pydata/pandas |
|
No means when I am removing it, I am not getting any error. It comes only after inserting it |
|
So, without the instead of , it passes? OK, I'll take a look on Friday |
|
Yes it got passed. Thank you, but I wanted to know how? And it isn't mentioned anywhere clearly? |
MarcoGorelli
left a comment
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.
deprecate_nonkeyword_arguments will raise a warning if any argument is passed as positional (except for method). If you pass axis as positional, it'll raise a warning - that's why the test now passes. If this isn't documented clearly in deprecate_nonkeyword_arguments, then feel free to open a PR to clarify it
Could you address https://github.com/pandas-dev/pandas/pull/41699/files#r641915415 and https://github.com/pandas-dev/pandas/pull/41699/files#r641909565 please?
| ) | ||
| expected = Series([1.0, 1.0, 1.0, 1.0], index=idx) | ||
|
|
||
| expected.index.freq = "3s" |
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.
@jbrockmendel in other tests I've seen you do
expected.index._data.freq = "3s"
- is that preferrable here, or is this OK?
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.
the ._data.freq = is preferable
|
Thanks @Anupam-USP |
…s-dev#41699) * ENH: Deprecate non-keyword arguments for interpolate * ENH: Deprecate non-keyword arguments for interpolate * ENH: Deprecate non-keyword arguments for interpolate * ENH: Deprecate non-keyword arguments for interpolate * ENH: Deprecate non-keyword arguments for interpolate * ENH: Deprecate non-keyword arguments for interpolate * ENH: Deprecate non-keyword arguments for interpolate * ENH: Deprecate non-keyword arguments for interpolate * ENH: Deprecate non-keyword arguments for interpolate * ENH: Deprecate non-keyword arguments for interpolate * ENH: Deprecate non-keyword arguments for interpolate * Update pandas/tests/resample/test_deprecated.py Co-authored-by: Marco Edward Gorelli <[email protected]>


inplace#41485