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
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/whatsnew/v1.3.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,7 @@ Deprecations
- Deprecated passing arguments as positional (except for ``"codes"``) in :meth:`MultiIndex.codes` (:issue:`41485`)
- Deprecated passing arguments as positional in :meth:`Index.set_names` and :meth:`MultiIndex.set_names` (except for ``names``) (:issue:`41485`)
- Deprecated passing arguments (apart from ``cond`` and ``other``) as positional in :meth:`DataFrame.mask` and :meth:`Series.mask` (:issue:`41485`)
- Deprecated passing arguments as positional in :meth:`Resampler.interpolate` (other than ``"method"``) (:issue:`41485`)
- Deprecated passing arguments as positional in :meth:`DataFrame.clip` and :meth:`Series.clip` (other than ``"upper"`` and ``"lower"``) (:issue:`41485`)
- Deprecated special treatment of lists with first element a Categorical in the :class:`DataFrame` constructor; pass as ``pd.DataFrame({col: categorical, ...})`` instead (:issue:`38845`)
- Deprecated passing arguments as positional (except for ``"method"``) in :meth:`DataFrame.interpolate` and :meth:`Series.interpolate` (:issue:`41485`)
Expand Down
2 changes: 2 additions & 0 deletions pandas/core/resample.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
from pandas.util._decorators import (
Appender,
Substitution,
deprecate_nonkeyword_arguments,
doc,
)

Expand Down Expand Up @@ -832,6 +833,7 @@ def fillna(self, method, limit=None):
"""
return self._upsample(method, limit=limit)

@deprecate_nonkeyword_arguments(version=None, allowed_args=["self", "method"])
@doc(NDFrame.interpolate, **_shared_docs_kwargs)
def interpolate(
self,
Expand Down
33 changes: 33 additions & 0 deletions pandas/tests/resample/test_deprecated.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,3 +278,36 @@ def test_resample_base_with_timedeltaindex():

tm.assert_index_equal(without_base.index, exp_without_base)
tm.assert_index_equal(with_base.index, exp_with_base)


def test_interpolate_posargs_deprecation():
MarcoGorelli marked this conversation as resolved.
Show resolved Hide resolved
# GH 41485
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)


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.


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


df = DataFrame(
{
"ds": [
"1992-08-27 07:46:48",
"1992-08-27 07:46:51",
"1992-08-27 07:46:54",
"1992-08-27 07:46:57",
],
"y": [1.0, 1.0, 1.0, 1.0],
}
)
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


tm.assert_frame_equal(result, expected)