Skip to content
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

Merged

Conversation

Anupam-USP
Copy link
Contributor

@Anupam-USP Anupam-USP commented May 28, 2021

@pep8speaks
Copy link

pep8speaks commented May 28, 2021

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

Copy link
Member

@MarcoGorelli MarcoGorelli left a 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

@Anupam-USP
Copy link
Contributor Author

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?

Comment on lines 283 to 295
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])
Copy link
Member

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

@MarcoGorelli
Copy link
Member

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?

see https://pandas.pydata.org/pandas-docs/stable/development/contributing.html#pre-commit

Copy link
Member

@MarcoGorelli MarcoGorelli left a 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?

pandas/tests/resample/test_deprecated.py Show resolved Hide resolved
Comment on lines 286 to 292
data = StringIO(
"""\
Values
1992-08-27 07:46:48,1
1992-08-27 07:46:59,4"""
)
s = pd.read_csv(data, squeeze=True)
Copy link
Member

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]})

Comment on lines 303 to 312
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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

likewise, construct this directly

Copy link
Contributor Author

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!

@Anupam-USP
Copy link
Contributor Author

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?

Comment on lines 290 to 293
msg = (
r"In a future version of pandas all arguments of DataFrame\.interpolate "
r"except for the argument 'method' will be keyword-only"
)
Copy link
Member

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?

Copy link
Contributor Author

@Anupam-USP Anupam-USP May 29, 2021

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'

Copy link
Member

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

Copy link
Contributor Author

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.

Comment on lines 309 to 311
expected = Series(
df.iloc[:, 1].values.reshape(-1), index=pd.to_datetime(df.iloc[:, 0].values)
)
Copy link
Member

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

Comment on lines 295 to 296
with tm.assert_produces_warning(FutureWarning, match=msg):
result = s.resample("3s").interpolate("linear")
Copy link
Member

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

Comment on lines 285 to 288
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)
)
Copy link
Member

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?

Copy link
Contributor Author

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

Copy link
Member

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)

Comment on lines 290 to 293
msg = (
r"In a future version of pandas all arguments of DataFrame\.interpolate "
r"except for the argument 'method' will be keyword-only"
)
Copy link
Member

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")
Copy link
Member

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

Copy link
Contributor Author

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

Copy link
Member

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 😄

@jreback jreback added Deprecate Functionality to remove in pandas Resample resample method labels May 31, 2021
@jreback
Copy link
Contributor

jreback commented May 31, 2021

@Anupam-USP if you can rebase & update

@Anupam-USP
Copy link
Contributor Author

I am not able to get rid of this issue AssertionError: Did not see expected warning of class 'FutureWarning' when I am using with tm.assert_produces_warning. Sorry I tried!

@MarcoGorelli
Copy link
Member

I am not able to get rid of this issue AssertionError: Did not see expected warning of class 'FutureWarning' when I am using with tm.assert_produces_warning. Sorry I tried!

What happens if you remove the tm.assert_produces_warning line and run the test? Can you show your complete output?

@Anupam-USP
Copy link
Contributor Author

Anupam-USP commented Jun 2, 2021

image
image

This happens when i insert the test, otherwise checks are getting passed without it

@MarcoGorelli
Copy link
Member

MarcoGorelli commented Jun 2, 2021

otherwise checks are getting passed without it

Do they still pass if you also change

result = s.resample("3s").interpolate("linear")

to

result = s.resample("3s").interpolate("linear", 0)

?
(you're deprecating axis as positional, but not method). Then, this should raise some warning


If you want, let's continue this discussion on gitter https://gitter.im/pydata/pandas

@Anupam-USP
Copy link
Contributor Author

No means when I am removing it, I am not getting any error. It comes only after inserting it

@MarcoGorelli
Copy link
Member

So, without the tm.asssert_produces_warning line, and with

result = s.resample("3s").interpolate("linear", 0)

instead of

result = s.resample("3s").interpolate("linear")

, it passes? OK, I'll take a look on Friday

@Anupam-USP
Copy link
Contributor Author

Yes it got passed. Thank you, but I wanted to know how? And it isn't mentioned anywhere clearly?

Copy link
Member

@MarcoGorelli MarcoGorelli left a 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"
Copy link
Member

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?

Copy link
Member

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

@simonjayhawkins simonjayhawkins changed the title ENH: Deprecate non-keyword arguments for interpolate ENH: Deprecate non-keyword arguments for Resampler.interpolate Jun 4, 2021
@simonjayhawkins simonjayhawkins added this to the 1.3 milestone Jun 4, 2021
@MarcoGorelli MarcoGorelli merged commit 3f67dc3 into pandas-dev:master Jun 5, 2021
@MarcoGorelli
Copy link
Member

Thanks @Anupam-USP

JulianWgs pushed a commit to JulianWgs/pandas that referenced this pull request Jul 3, 2021
…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 <marcogorelli@protonmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Deprecate Functionality to remove in pandas Resample resample method
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants