Skip to content

Commit c459c43

Browse files
mroeschkeproost
authored andcommitted
DEPR: Remove how, fill_method, and limit from resample (pandas-dev#30139)
1 parent 1549306 commit c459c43

File tree

6 files changed

+59
-104
lines changed

6 files changed

+59
-104
lines changed

doc/source/whatsnew/v1.0.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,7 @@ or ``matplotlib.Axes.plot``. See :ref:`plotting.formatters` for more.
600600
- In :func:`concat` the default value for ``sort`` has been changed from ``None`` to ``False`` (:issue:`20613`)
601601
- Removed previously deprecated "raise_conflict" argument from :meth:`DataFrame.update`, use "errors" instead (:issue:`23585`)
602602
- Removed previously deprecated keyword "n" from :meth:`DatetimeIndex.shift`, :meth:`TimedeltaIndex.shift`, :meth:`PeriodIndex.shift`, use "periods" instead (:issue:`22458`)
603+
- Removed previously deprecated keywords ``how``, ``fill_method``, and ``limit`` from :meth:`DataFrame.resample` (:issue:`30139`)
603604
- Passing an integer to :meth:`Series.fillna` or :meth:`DataFrame.fillna` with ``timedelta64[ns]`` dtype now raises ``TypeError`` (:issue:`24694`)
604605
- Passing multiple axes to :meth:`DataFrame.dropna` is no longer supported (:issue:`20995`)
605606
- Removed previously deprecated :meth:`Series.nonzero`, use `to_numpy().nonzero()` instead (:issue:`24048`)

pandas/core/generic.py

+2-24
Original file line numberDiff line numberDiff line change
@@ -7728,15 +7728,12 @@ def between_time(
77287728
def resample(
77297729
self,
77307730
rule,
7731-
how: Optional[str] = None,
77327731
axis=0,
7733-
fill_method: Optional[str] = None,
77347732
closed: Optional[str] = None,
77357733
label: Optional[str] = None,
77367734
convention: str = "start",
77377735
kind: Optional[str] = None,
77387736
loffset=None,
7739-
limit: Optional[int] = None,
77407737
base: int = 0,
77417738
on=None,
77427739
level=None,
@@ -7753,22 +7750,10 @@ def resample(
77537750
----------
77547751
rule : DateOffset, Timedelta or str
77557752
The offset string or object representing target conversion.
7756-
how : str
7757-
Method for down/re-sampling, default to 'mean' for downsampling.
7758-
7759-
.. deprecated:: 0.18.0
7760-
The new syntax is ``.resample(...).mean()``, or
7761-
``.resample(...).apply(<func>)``
77627753
axis : {0 or 'index', 1 or 'columns'}, default 0
77637754
Which axis to use for up- or down-sampling. For `Series` this
77647755
will default to 0, i.e. along the rows. Must be
77657756
`DatetimeIndex`, `TimedeltaIndex` or `PeriodIndex`.
7766-
fill_method : str, default None
7767-
Filling method for upsampling.
7768-
7769-
.. deprecated:: 0.18.0
7770-
The new syntax is ``.resample(...).<func>()``,
7771-
e.g. ``.resample(...).pad()``
77727757
closed : {'right', 'left'}, default None
77737758
Which side of bin interval is closed. The default is 'left'
77747759
for all frequency offsets except for 'M', 'A', 'Q', 'BM',
@@ -7786,10 +7771,6 @@ def resample(
77867771
By default the input representation is retained.
77877772
loffset : timedelta, default None
77887773
Adjust the resampled time labels.
7789-
limit : int, default None
7790-
Maximum size gap when reindexing with `fill_method`.
7791-
7792-
.. deprecated:: 0.18.0
77937774
base : int, default 0
77947775
For frequencies that evenly subdivide 1 day, the "origin" of the
77957776
aggregated intervals. For example, for '5min' frequency, base could
@@ -8021,10 +8002,10 @@ def resample(
80218002
2000-01-04 36 90
80228003
"""
80238004

8024-
from pandas.core.resample import resample, _maybe_process_deprecations
8005+
from pandas.core.resample import resample
80258006

80268007
axis = self._get_axis_number(axis)
8027-
r = resample(
8008+
return resample(
80288009
self,
80298010
freq=rule,
80308011
label=label,
@@ -8037,9 +8018,6 @@ def resample(
80378018
key=on,
80388019
level=level,
80398020
)
8040-
return _maybe_process_deprecations(
8041-
r, how=how, fill_method=fill_method, limit=limit
8042-
)
80438021

80448022
def first(self, offset):
80458023
"""

pandas/core/resample.py

+1-55
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
from datetime import timedelta
33
from textwrap import dedent
44
from typing import Dict, no_type_check
5-
import warnings
65

76
import numpy as np
87

@@ -953,58 +952,6 @@ def h(self, _method=method):
953952
setattr(Resampler, method, h)
954953

955954

956-
def _maybe_process_deprecations(r, how=None, fill_method=None, limit=None):
957-
"""
958-
Potentially we might have a deprecation warning, show it
959-
but call the appropriate methods anyhow.
960-
"""
961-
962-
if how is not None:
963-
964-
# .resample(..., how='sum')
965-
if isinstance(how, str):
966-
method = "{0}()".format(how)
967-
968-
# .resample(..., how=lambda x: ....)
969-
else:
970-
method = ".apply(<func>)"
971-
972-
# if we have both a how and fill_method, then show
973-
# the following warning
974-
if fill_method is None:
975-
warnings.warn(
976-
"how in .resample() is deprecated\n"
977-
"the new syntax is "
978-
".resample(...).{method}".format(method=method),
979-
FutureWarning,
980-
stacklevel=3,
981-
)
982-
r = r.aggregate(how)
983-
984-
if fill_method is not None:
985-
986-
# show the prior function call
987-
method = "." + method if how is not None else ""
988-
989-
args = "limit={0}".format(limit) if limit is not None else ""
990-
warnings.warn(
991-
"fill_method is deprecated to .resample()\n"
992-
"the new syntax is .resample(...){method}"
993-
".{fill_method}({args})".format(
994-
method=method, fill_method=fill_method, args=args
995-
),
996-
FutureWarning,
997-
stacklevel=3,
998-
)
999-
1000-
if how is not None:
1001-
r = getattr(r, fill_method)(limit=limit)
1002-
else:
1003-
r = r.aggregate(fill_method, limit=limit)
1004-
1005-
return r
1006-
1007-
1008955
class _GroupByMixin(GroupByMixin):
1009956
"""
1010957
Provide the groupby facilities.
@@ -1342,8 +1289,7 @@ def get_resampler_for_grouping(
13421289

13431290
tg = TimeGrouper(freq=rule, **kwargs)
13441291
resampler = tg._get_resampler(groupby.obj, kind=kind)
1345-
r = resampler._get_resampler_for_grouping(groupby=groupby)
1346-
return _maybe_process_deprecations(r, how=how, fill_method=fill_method, limit=limit)
1292+
return resampler._get_resampler_for_grouping(groupby=groupby)
13471293

13481294

13491295
class TimeGrouper(Grouper):

pandas/tests/resample/test_base.py

+11-18
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,8 @@ def test_resample_empty_dtypes(index, dtype, resample_method):
207207

208208

209209
@all_ts
210-
def test_resample_loffset_arg_type(frame, create_index):
210+
@pytest.mark.parametrize("arg", ["mean", {"value": "mean"}, ["mean"]])
211+
def test_resample_loffset_arg_type(frame, create_index, arg):
211212
# GH 13218, 15002
212213
df = frame
213214
expected_means = [df.values[i : i + 2].mean() for i in range(0, len(df.values), 2)]
@@ -220,26 +221,18 @@ def test_resample_loffset_arg_type(frame, create_index):
220221
expected_index += timedelta(hours=2)
221222
expected = DataFrame({"value": expected_means}, index=expected_index)
222223

223-
for arg in ["mean", {"value": "mean"}, ["mean"]]:
224+
result_agg = df.resample("2D", loffset="2H").agg(arg)
224225

225-
result_agg = df.resample("2D", loffset="2H").agg(arg)
226+
if isinstance(arg, list):
227+
expected.columns = pd.MultiIndex.from_tuples([("value", "mean")])
226228

227-
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
228-
result_how = df.resample("2D", how=arg, loffset="2H")
229-
230-
if isinstance(arg, list):
231-
expected.columns = pd.MultiIndex.from_tuples([("value", "mean")])
232-
233-
# GH 13022, 7687 - TODO: fix resample w/ TimedeltaIndex
234-
if isinstance(expected.index, TimedeltaIndex):
235-
msg = "DataFrame are different"
236-
with pytest.raises(AssertionError, match=msg):
237-
tm.assert_frame_equal(result_agg, expected)
238-
with pytest.raises(AssertionError, match=msg):
239-
tm.assert_frame_equal(result_how, expected)
240-
else:
229+
# GH 13022, 7687 - TODO: fix resample w/ TimedeltaIndex
230+
if isinstance(expected.index, TimedeltaIndex):
231+
msg = "DataFrame are different"
232+
with pytest.raises(AssertionError, match=msg):
241233
tm.assert_frame_equal(result_agg, expected)
242-
tm.assert_frame_equal(result_how, expected)
234+
else:
235+
tm.assert_frame_equal(result_agg, expected)
243236

244237

245238
@all_ts

pandas/tests/resample/test_period_index.py

-3
Original file line numberDiff line numberDiff line change
@@ -732,12 +732,9 @@ def test_loffset_returns_datetimeindex(self, frame, kind, agg_arg):
732732
expected = DataFrame({"value": expected_means}, index=expected_index)
733733

734734
result_agg = df.resample("2D", loffset="2H", kind=kind).agg(agg_arg)
735-
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
736-
result_how = df.resample("2D", how=agg_arg, loffset="2H", kind=kind)
737735
if isinstance(agg_arg, list):
738736
expected.columns = pd.MultiIndex.from_tuples([("value", "mean")])
739737
tm.assert_frame_equal(result_agg, expected)
740-
tm.assert_frame_equal(result_how, expected)
741738

742739
@pytest.mark.parametrize("freq, period_mult", [("H", 24), ("12H", 2)])
743740
@pytest.mark.parametrize("kind", [None, "period"])

pandas/tests/resample/test_resample_api.py

+44-4
Original file line numberDiff line numberDiff line change
@@ -179,17 +179,57 @@ def test_downsample_but_actually_upsampling():
179179

180180
def test_combined_up_downsampling_of_irregular():
181181

182-
# since we are reallydoing an operation like this
182+
# since we are really doing an operation like this
183183
# ts2.resample('2s').mean().ffill()
184184
# preserve these semantics
185185

186186
rng = pd.date_range("1/1/2012", periods=100, freq="S")
187187
ts = Series(np.arange(len(rng)), index=rng)
188188
ts2 = ts.iloc[[0, 1, 2, 3, 5, 7, 11, 15, 16, 25, 30]]
189189

190-
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
191-
result = ts2.resample("2s", how="mean", fill_method="ffill")
192-
expected = ts2.resample("2s").mean().ffill()
190+
result = ts2.resample("2s").mean().ffill()
191+
expected = Series(
192+
[
193+
0.5,
194+
2.5,
195+
5.0,
196+
7.0,
197+
7.0,
198+
11.0,
199+
11.0,
200+
15.0,
201+
16.0,
202+
16.0,
203+
16.0,
204+
16.0,
205+
25.0,
206+
25.0,
207+
25.0,
208+
30.0,
209+
],
210+
index=pd.DatetimeIndex(
211+
[
212+
"2012-01-01 00:00:00",
213+
"2012-01-01 00:00:02",
214+
"2012-01-01 00:00:04",
215+
"2012-01-01 00:00:06",
216+
"2012-01-01 00:00:08",
217+
"2012-01-01 00:00:10",
218+
"2012-01-01 00:00:12",
219+
"2012-01-01 00:00:14",
220+
"2012-01-01 00:00:16",
221+
"2012-01-01 00:00:18",
222+
"2012-01-01 00:00:20",
223+
"2012-01-01 00:00:22",
224+
"2012-01-01 00:00:24",
225+
"2012-01-01 00:00:26",
226+
"2012-01-01 00:00:28",
227+
"2012-01-01 00:00:30",
228+
],
229+
dtype="datetime64[ns]",
230+
freq="2S",
231+
),
232+
)
193233
tm.assert_series_equal(result, expected)
194234

195235

0 commit comments

Comments
 (0)