-
-
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
CLN: enforce deprecation of the kind
keyword on df.resample/ser.resample
#58125
Merged
mroeschke
merged 15 commits into
pandas-dev:main
from
natmokval:cln-enforce-depr-kwd-kind-series-df
Apr 19, 2024
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
df59899
enforced deprecation of the kind keyword on df.resample/ser.resample
natmokval c970eba
fix tests
natmokval 275524e
fix tests
natmokval e853b4a
fix tests
natmokval 65627ec
Merge branch 'main' into cln-enforce-depr-kwd-kind-series-df
natmokval 06592df
add a note to v3.0.0
natmokval 61f50e5
return a blank line in resample.py back
natmokval 9bdd90f
Merge branch 'main' into cln-enforce-depr-kwd-kind-series-df
natmokval c50848e
remove leftover
natmokval 2b507af
remove kind from get_resampler, delete test
natmokval 0fff4fd
Merge branch 'main' into cln-enforce-depr-kwd-kind-series-df
natmokval 6e511ad
remove kwd kind from _get_resampler, fix test
natmokval 35ae66f
remove kwd kind from the class Resampler
natmokval 8ca1597
remove kind from TimeGrouper
natmokval 9c0c230
inline the parameter freq in test_resample_5minute
natmokval File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
kind
fromget_resampler
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.
Shouldn't all/most of the
kind
keywords inresample.py
be 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;
kind
can be removed fromResampler
andTimeGrouper
. I have updated this PR. Could you please take a look?