-
-
Couldn't load subscription status.
- Fork 19.2k
CLN: enforce deprecation of the kind keyword on df.resample/ser.resample
#58125
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
df59899
c970eba
275524e
e853b4a
65627ec
06592df
61f50e5
9bdd90f
c50848e
2b507af
0fff4fd
6e511ad
35ae66f
8ca1597
9c0c230
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 |
|---|---|---|
|
|
@@ -441,19 +441,6 @@ def test_resample_frame_basic_M_A(freq, unit): | |
| tm.assert_series_equal(result["A"], df["A"].resample(freq).mean()) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("freq", ["W-WED", "ME"]) | ||
| def test_resample_frame_basic_kind(freq, unit): | ||
| df = DataFrame( | ||
| np.random.default_rng(2).standard_normal((10, 4)), | ||
| columns=Index(list("ABCD"), dtype=object), | ||
| index=date_range("2000-01-01", periods=10, freq="B"), | ||
| ) | ||
| df.index = df.index.as_unit(unit) | ||
| msg = "The 'kind' keyword in DataFrame.resample is deprecated" | ||
| with tm.assert_produces_warning(FutureWarning, match=msg): | ||
| df.resample(freq, kind="period").mean() | ||
|
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 think you can remove this test entirely 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, done |
||
|
|
||
|
|
||
| def test_resample_upsample(unit): | ||
| # from daily | ||
| dti = date_range( | ||
|
|
@@ -665,9 +652,7 @@ def test_resample_timestamp_to_period( | |
| ts = simple_date_range_series("1/1/1990", "1/1/2000") | ||
| ts.index = ts.index.as_unit(unit) | ||
|
|
||
| msg = "The 'kind' keyword in Series.resample is deprecated" | ||
| with tm.assert_produces_warning(FutureWarning, match=msg): | ||
| result = ts.resample(freq, kind="period").mean() | ||
| result = ts.resample(freq).mean().to_period() | ||
| expected = ts.resample(freq).mean() | ||
| expected.index = period_range(**expected_kwargs) | ||
| tm.assert_series_equal(result, expected) | ||
|
|
@@ -985,9 +970,7 @@ def test_resample_to_period_monthly_buglet(unit): | |
| rng = date_range("1/1/2000", "12/31/2000").as_unit(unit) | ||
| ts = Series(np.random.default_rng(2).standard_normal(len(rng)), index=rng) | ||
|
|
||
| msg = "The 'kind' keyword in Series.resample is deprecated" | ||
| with tm.assert_produces_warning(FutureWarning, match=msg): | ||
| result = ts.resample("ME", kind="period").mean() | ||
| result = ts.resample("ME").mean().to_period() | ||
| exp_index = period_range("Jan-2000", "Dec-2000", freq="M") | ||
| tm.assert_index_equal(result.index, exp_index) | ||
|
|
||
|
|
@@ -1109,18 +1092,15 @@ def test_resample_anchored_intraday(unit): | |
| df = DataFrame(rng.month, index=rng) | ||
|
|
||
| result = df.resample("ME").mean() | ||
| msg = "The 'kind' keyword in DataFrame.resample is deprecated" | ||
| with tm.assert_produces_warning(FutureWarning, match=msg): | ||
| expected = df.resample("ME", kind="period").mean().to_timestamp(how="end") | ||
| expected = df.resample("ME").mean().to_period() | ||
| expected = expected.to_timestamp(how="end") | ||
| expected.index += Timedelta(1, "ns") - Timedelta(1, "D") | ||
| expected.index = expected.index.as_unit(unit)._with_freq("infer") | ||
| assert expected.index.freq == "ME" | ||
| tm.assert_frame_equal(result, expected) | ||
|
|
||
| result = df.resample("ME", closed="left").mean() | ||
| msg = "The 'kind' keyword in DataFrame.resample is deprecated" | ||
| with tm.assert_produces_warning(FutureWarning, match=msg): | ||
| exp = df.shift(1, freq="D").resample("ME", kind="period").mean() | ||
| exp = df.shift(1, freq="D").resample("ME").mean().to_period() | ||
| exp = exp.to_timestamp(how="end") | ||
|
|
||
| exp.index = exp.index + Timedelta(1, "ns") - Timedelta(1, "D") | ||
|
|
@@ -1134,21 +1114,17 @@ def test_resample_anchored_intraday2(unit): | |
| df = DataFrame(rng.month, index=rng) | ||
|
|
||
| result = df.resample("QE").mean() | ||
| msg = "The 'kind' keyword in DataFrame.resample is deprecated" | ||
| with tm.assert_produces_warning(FutureWarning, match=msg): | ||
| expected = df.resample("QE", kind="period").mean().to_timestamp(how="end") | ||
| expected = df.resample("QE").mean().to_period() | ||
| expected = expected.to_timestamp(how="end") | ||
| expected.index += Timedelta(1, "ns") - Timedelta(1, "D") | ||
| expected.index._data.freq = "QE" | ||
| expected.index._freq = lib.no_default | ||
| expected.index = expected.index.as_unit(unit) | ||
| tm.assert_frame_equal(result, expected) | ||
|
|
||
| result = df.resample("QE", closed="left").mean() | ||
| msg = "The 'kind' keyword in DataFrame.resample is deprecated" | ||
| with tm.assert_produces_warning(FutureWarning, match=msg): | ||
| expected = ( | ||
| df.shift(1, freq="D").resample("QE", kind="period", closed="left").mean() | ||
| ) | ||
| expected = df.shift(1, freq="D").resample("QE").mean() | ||
| expected = expected.to_period() | ||
| expected = expected.to_timestamp(how="end") | ||
| expected.index += Timedelta(1, "ns") - Timedelta(1, "D") | ||
| expected.index._data.freq = "QE" | ||
|
|
@@ -1205,9 +1181,7 @@ def test_corner_cases_date(simple_date_range_series, unit): | |
| # resample to periods | ||
| ts = simple_date_range_series("2000-04-28", "2000-04-30 11:00", freq="h") | ||
| ts.index = ts.index.as_unit(unit) | ||
| msg = "The 'kind' keyword in Series.resample is deprecated" | ||
| with tm.assert_produces_warning(FutureWarning, match=msg): | ||
| result = ts.resample("ME", kind="period").mean() | ||
| result = ts.resample("ME").mean().to_period() | ||
| assert len(result) == 1 | ||
| assert result.index[0] == Period("2000-04", freq="M") | ||
|
|
||
|
|
||
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 dont see a diff in pandas.core.resample; doesn't the keyword need to be removed there too?
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.
sorry, my mistake. I removed the keyword
kindfromget_resamplerThere 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.
Shouldn't all/most of the
kindkeywords inresample.pybe removable?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.
Thanks for the comment. Yes, it was my mistake;
kindcan be removed fromResamplerandTimeGrouper. I have updated this PR. Could you please take a look?