Skip to content

Commit d00928e

Browse files
authored
DEPR: Enforce deprecation of mad and tshift (#49252)
1 parent a19b981 commit d00928e

31 files changed

+68
-559
lines changed

asv_bench/benchmarks/groupby.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
"pct_change",
3636
"min",
3737
"var",
38-
"mad",
3938
"describe",
4039
"std",
4140
"quantile",
@@ -52,7 +51,6 @@
5251
"cummax",
5352
"pct_change",
5453
"var",
55-
"mad",
5654
"describe",
5755
"std",
5856
},
@@ -437,7 +435,6 @@ class GroupByMethods:
437435
"first",
438436
"head",
439437
"last",
440-
"mad",
441438
"max",
442439
"min",
443440
"median",
@@ -483,7 +480,7 @@ def setup(self, dtype, method, application, ncols):
483480

484481
if method == "describe":
485482
ngroups = 20
486-
elif method in ["mad", "skew"]:
483+
elif method == "skew":
487484
ngroups = 100
488485
else:
489486
ngroups = 1000

asv_bench/benchmarks/stat_ops.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import pandas as pd
44

5-
ops = ["mean", "sum", "median", "std", "skew", "kurt", "mad", "prod", "sem", "var"]
5+
ops = ["mean", "sum", "median", "std", "skew", "kurt", "prod", "sem", "var"]
66

77

88
class FrameOps:
@@ -11,9 +11,6 @@ class FrameOps:
1111
param_names = ["op", "dtype", "axis"]
1212

1313
def setup(self, op, dtype, axis):
14-
if op == "mad" and dtype == "Int64":
15-
# GH-33036, GH#33600
16-
raise NotImplementedError
1714
values = np.random.randn(100000, 4)
1815
if dtype == "Int64":
1916
values = values.astype(int)

doc/redirects.csv

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,6 @@ generated/pandas.core.groupby.DataFrameGroupBy.filter,../reference/api/pandas.co
186186
generated/pandas.core.groupby.DataFrameGroupBy.hist,../reference/api/pandas.core.groupby.DataFrameGroupBy.hist
187187
generated/pandas.core.groupby.DataFrameGroupBy.idxmax,../reference/api/pandas.core.groupby.DataFrameGroupBy.idxmax
188188
generated/pandas.core.groupby.DataFrameGroupBy.idxmin,../reference/api/pandas.core.groupby.DataFrameGroupBy.idxmin
189-
generated/pandas.core.groupby.DataFrameGroupBy.mad,../reference/api/pandas.core.groupby.DataFrameGroupBy.mad
190189
generated/pandas.core.groupby.DataFrameGroupBy.pct_change,../reference/api/pandas.core.groupby.DataFrameGroupBy.pct_change
191190
generated/pandas.core.groupby.DataFrameGroupBy.plot,../reference/api/pandas.core.groupby.DataFrameGroupBy.plot
192191
generated/pandas.core.groupby.DataFrameGroupBy.quantile,../reference/api/pandas.core.groupby.DataFrameGroupBy.quantile
@@ -196,7 +195,6 @@ generated/pandas.core.groupby.DataFrameGroupBy.shift,../reference/api/pandas.cor
196195
generated/pandas.core.groupby.DataFrameGroupBy.size,../reference/api/pandas.core.groupby.DataFrameGroupBy.size
197196
generated/pandas.core.groupby.DataFrameGroupBy.skew,../reference/api/pandas.core.groupby.DataFrameGroupBy.skew
198197
generated/pandas.core.groupby.DataFrameGroupBy.take,../reference/api/pandas.core.groupby.DataFrameGroupBy.take
199-
generated/pandas.core.groupby.DataFrameGroupBy.tshift,../reference/api/pandas.core.groupby.DataFrameGroupBy.tshift
200198
generated/pandas.core.groupby.GroupBy.agg,../reference/api/pandas.core.groupby.GroupBy.agg
201199
generated/pandas.core.groupby.GroupBy.aggregate,../reference/api/pandas.core.groupby.GroupBy.aggregate
202200
generated/pandas.core.groupby.GroupBy.all,../reference/api/pandas.core.groupby.GroupBy.all
@@ -415,7 +413,6 @@ generated/pandas.DataFrame.le,../reference/api/pandas.DataFrame.le
415413
generated/pandas.DataFrame.loc,../reference/api/pandas.DataFrame.loc
416414
generated/pandas.DataFrame.lookup,../reference/api/pandas.DataFrame.lookup
417415
generated/pandas.DataFrame.lt,../reference/api/pandas.DataFrame.lt
418-
generated/pandas.DataFrame.mad,../reference/api/pandas.DataFrame.mad
419416
generated/pandas.DataFrame.mask,../reference/api/pandas.DataFrame.mask
420417
generated/pandas.DataFrame.max,../reference/api/pandas.DataFrame.max
421418
generated/pandas.DataFrame.mean,../reference/api/pandas.DataFrame.mean
@@ -528,7 +525,6 @@ generated/pandas.DataFrame.transform,../reference/api/pandas.DataFrame.transform
528525
generated/pandas.DataFrame.transpose,../reference/api/pandas.DataFrame.transpose
529526
generated/pandas.DataFrame.truediv,../reference/api/pandas.DataFrame.truediv
530527
generated/pandas.DataFrame.truncate,../reference/api/pandas.DataFrame.truncate
531-
generated/pandas.DataFrame.tshift,../reference/api/pandas.DataFrame.tshift
532528
generated/pandas.DataFrame.tz_convert,../reference/api/pandas.DataFrame.tz_convert
533529
generated/pandas.DataFrame.tz_localize,../reference/api/pandas.DataFrame.tz_localize
534530
generated/pandas.DataFrame.unstack,../reference/api/pandas.DataFrame.unstack
@@ -1097,7 +1093,6 @@ generated/pandas.Series.last_valid_index,../reference/api/pandas.Series.last_val
10971093
generated/pandas.Series.le,../reference/api/pandas.Series.le
10981094
generated/pandas.Series.loc,../reference/api/pandas.Series.loc
10991095
generated/pandas.Series.lt,../reference/api/pandas.Series.lt
1100-
generated/pandas.Series.mad,../reference/api/pandas.Series.mad
11011096
generated/pandas.Series.map,../reference/api/pandas.Series.map
11021097
generated/pandas.Series.mask,../reference/api/pandas.Series.mask
11031098
generated/pandas.Series.max,../reference/api/pandas.Series.max
@@ -1266,7 +1261,6 @@ generated/pandas.Series.transform,../reference/api/pandas.Series.transform
12661261
generated/pandas.Series.transpose,../reference/api/pandas.Series.transpose
12671262
generated/pandas.Series.truediv,../reference/api/pandas.Series.truediv
12681263
generated/pandas.Series.truncate,../reference/api/pandas.Series.truncate
1269-
generated/pandas.Series.tshift,../reference/api/pandas.Series.tshift
12701264
generated/pandas.Series.tz_convert,../reference/api/pandas.Series.tz_convert
12711265
generated/pandas.Series.tz_localize,../reference/api/pandas.Series.tz_localize
12721266
generated/pandas.Series.unique,../reference/api/pandas.Series.unique

doc/source/reference/frame.rst

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,6 @@ Computations / descriptive stats
151151
DataFrame.eval
152152
DataFrame.kurt
153153
DataFrame.kurtosis
154-
DataFrame.mad
155154
DataFrame.max
156155
DataFrame.mean
157156
DataFrame.median
@@ -268,7 +267,6 @@ Time Series-related
268267
DataFrame.asof
269268
DataFrame.shift
270269
DataFrame.slice_shift
271-
DataFrame.tshift
272270
DataFrame.first_valid_index
273271
DataFrame.last_valid_index
274272
DataFrame.resample

doc/source/reference/groupby.rst

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ Function application
8484
DataFrameGroupBy.idxmax
8585
DataFrameGroupBy.idxmin
8686
DataFrameGroupBy.last
87-
DataFrameGroupBy.mad
8887
DataFrameGroupBy.max
8988
DataFrameGroupBy.mean
9089
DataFrameGroupBy.median
@@ -108,7 +107,6 @@ Function application
108107
DataFrameGroupBy.var
109108
DataFrameGroupBy.tail
110109
DataFrameGroupBy.take
111-
DataFrameGroupBy.tshift
112110
DataFrameGroupBy.value_counts
113111

114112
``SeriesGroupBy`` computations / descriptive stats
@@ -138,7 +136,6 @@ Function application
138136
SeriesGroupBy.idxmin
139137
SeriesGroupBy.is_monotonic_increasing
140138
SeriesGroupBy.is_monotonic_decreasing
141-
SeriesGroupBy.mad
142139
SeriesGroupBy.max
143140
SeriesGroupBy.mean
144141
SeriesGroupBy.median
@@ -165,7 +162,6 @@ Function application
165162
SeriesGroupBy.var
166163
SeriesGroupBy.tail
167164
SeriesGroupBy.take
168-
SeriesGroupBy.tshift
169165
SeriesGroupBy.value_counts
170166

171167
Plotting and visualization

doc/source/reference/series.rst

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,6 @@ Computations / descriptive stats
148148
Series.diff
149149
Series.factorize
150150
Series.kurt
151-
Series.mad
152151
Series.max
153152
Series.mean
154153
Series.median
@@ -269,7 +268,6 @@ Time Series-related
269268
Series.tz_localize
270269
Series.at_time
271270
Series.between_time
272-
Series.tshift
273271
Series.slice_shift
274272

275273
Accessors

doc/source/user_guide/basics.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,6 @@ optional ``level`` parameter which applies only if the object has a
556556
``count``, Number of non-NA observations
557557
``sum``, Sum of values
558558
``mean``, Mean of values
559-
``mad``, Mean absolute deviation
560559
``median``, Arithmetic median of values
561560
``min``, Minimum
562561
``max``, Maximum

doc/source/whatsnew/v2.0.0.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,8 @@ Removal of prior version deprecations/changes
200200
- Removed ``pandas.SparseSeries`` and ``pandas.SparseDataFrame`` (:issue:`30642`)
201201
- Enforced disallowing a string column label into ``times`` in :meth:`DataFrame.ewm` (:issue:`43265`)
202202
- Enforced :meth:`Rolling.count` with ``min_periods=None`` to default to the size of the window (:issue:`31302`)
203-
-
203+
- Removed the deprecated method ``mad`` from pandas classes (:issue:`11787`)
204+
- Removed the deprecated method ``tshift`` from pandas classes (:issue:`11631`)
204205

205206
.. ---------------------------------------------------------------------------
206207
.. _whatsnew_200.performance:

pandas/core/apply.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ def apply_str(self) -> DataFrame | Series:
557557
sig = inspect.getfullargspec(func)
558558
arg_names = (*sig.args, *sig.kwonlyargs)
559559
if self.axis != 0 and (
560-
"axis" not in arg_names or f in ("corrwith", "mad", "skew")
560+
"axis" not in arg_names or f in ("corrwith", "skew")
561561
):
562562
raise ValueError(f"Operation {f} does not support axis=1")
563563
elif "axis" in arg_names:

pandas/core/generic.py

Lines changed: 1 addition & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ class NDFrame(PandasObject, indexing.IndexingMixin):
250250
_internal_names_set: set[str] = set(_internal_names)
251251
_accessors: set[str] = set()
252252
_hidden_attrs: frozenset[str] = frozenset(
253-
["_AXIS_NAMES", "_AXIS_NUMBERS", "get_values", "tshift"]
253+
["_AXIS_NAMES", "_AXIS_NUMBERS", "get_values"]
254254
)
255255
_metadata: list[str] = []
256256
_is_copy: weakref.ReferenceType[NDFrame] | None = None
@@ -10122,8 +10122,6 @@ def shift(
1012210122
Index.shift : Shift values of Index.
1012310123
DatetimeIndex.shift : Shift values of DatetimeIndex.
1012410124
PeriodIndex.shift : Shift values of PeriodIndex.
10125-
tshift : Shift the time index, using the index's frequency if
10126-
available.
1012710125
1012810126
Examples
1012910127
--------
@@ -10272,49 +10270,6 @@ def slice_shift(self: NDFrameT, periods: int = 1, axis: Axis = 0) -> NDFrameT:
1027210270
new_obj = new_obj.set_axis(shifted_axis, axis=axis, copy=False)
1027310271
return new_obj.__finalize__(self, method="slice_shift")
1027410272

10275-
@final
10276-
def tshift(self: NDFrameT, periods: int = 1, freq=None, axis: Axis = 0) -> NDFrameT:
10277-
"""
10278-
Shift the time index, using the index's frequency if available.
10279-
10280-
.. deprecated:: 1.1.0
10281-
Use `shift` instead.
10282-
10283-
Parameters
10284-
----------
10285-
periods : int
10286-
Number of periods to move, can be positive or negative.
10287-
freq : DateOffset, timedelta, or str, default None
10288-
Increment to use from the tseries module
10289-
or time rule expressed as a string (e.g. 'EOM').
10290-
axis : {0 or ‘index’, 1 or ‘columns’, None}, default 0
10291-
Corresponds to the axis that contains the Index.
10292-
For `Series` this parameter is unused and defaults to 0.
10293-
10294-
Returns
10295-
-------
10296-
shifted : Series/DataFrame
10297-
10298-
Notes
10299-
-----
10300-
If freq is not specified then tries to use the freq or inferred_freq
10301-
attributes of the index. If neither of those attributes exist, a
10302-
ValueError is thrown
10303-
"""
10304-
warnings.warn(
10305-
(
10306-
"tshift is deprecated and will be removed in a future version. "
10307-
"Please use shift instead."
10308-
),
10309-
FutureWarning,
10310-
stacklevel=find_stack_level(),
10311-
)
10312-
10313-
if freq is None:
10314-
freq = "infer"
10315-
10316-
return self.shift(periods, freq, axis)
10317-
1031810273
def truncate(
1031910274
self: NDFrameT,
1032010275
before=None,
@@ -11544,70 +11499,6 @@ def prod(
1154411499

1154511500
product = prod
1154611501

11547-
def mad(
11548-
self,
11549-
axis: Axis | None = None,
11550-
skipna: bool_t = True,
11551-
level: Level | None = None,
11552-
) -> Series | float:
11553-
"""
11554-
{desc}
11555-
11556-
.. deprecated:: 1.5.0
11557-
mad is deprecated.
11558-
11559-
Parameters
11560-
----------
11561-
axis : {axis_descr}
11562-
Axis for the function to be applied on.
11563-
For `Series` this parameter is unused and defaults to 0.
11564-
skipna : bool, default True
11565-
Exclude NA/null values when computing the result.
11566-
level : int or level name, default None
11567-
If the axis is a MultiIndex (hierarchical), count along a
11568-
particular level, collapsing into a {name1}.
11569-
11570-
Returns
11571-
-------
11572-
{name1} or {name2} (if level specified)\
11573-
{see_also}\
11574-
{examples}
11575-
"""
11576-
msg = (
11577-
"The 'mad' method is deprecated and will be removed in a future version. "
11578-
"To compute the same result, you may do `(df - df.mean()).abs().mean()`."
11579-
)
11580-
warnings.warn(msg, FutureWarning, stacklevel=find_stack_level())
11581-
11582-
if not is_bool(skipna):
11583-
warnings.warn(
11584-
"Passing None for skipna is deprecated and will raise in a future"
11585-
"version. Pass True instead. Only boolean values will be allowed "
11586-
"in the future.",
11587-
FutureWarning,
11588-
stacklevel=find_stack_level(),
11589-
)
11590-
skipna = True
11591-
if axis is None:
11592-
axis = self._stat_axis_number
11593-
if level is not None:
11594-
warnings.warn(
11595-
"Using the level keyword in DataFrame and Series aggregations is "
11596-
"deprecated and will be removed in a future version. Use groupby "
11597-
"instead. df.mad(level=1) should use df.groupby(level=1).mad()",
11598-
FutureWarning,
11599-
stacklevel=find_stack_level(),
11600-
)
11601-
return self._agg_by_level("mad", axis=axis, level=level, skipna=skipna)
11602-
11603-
data = self._get_numeric_data()
11604-
if axis == 0:
11605-
# error: Unsupported operand types for - ("NDFrame" and "float")
11606-
demeaned = data - data.mean(axis=0) # type: ignore[operator]
11607-
else:
11608-
demeaned = data.sub(data.mean(axis=1), axis=0)
11609-
return np.abs(demeaned).mean(axis=axis, skipna=skipna)
11610-
1161111502
@classmethod
1161211503
def _add_numeric_operations(cls) -> None:
1161311504
"""
@@ -11664,21 +11555,6 @@ def all(
1166411555

1166511556
setattr(cls, "all", all)
1166611557

11667-
@doc(
11668-
NDFrame.mad.__doc__,
11669-
desc="Return the mean absolute deviation of the values "
11670-
"over the requested axis.",
11671-
name1=name1,
11672-
name2=name2,
11673-
axis_descr=axis_descr,
11674-
see_also="",
11675-
examples="",
11676-
)
11677-
def mad(self, axis: Axis | None = None, skipna: bool_t = True, level=None):
11678-
return NDFrame.mad(self, axis, skipna, level)
11679-
11680-
setattr(cls, "mad", mad)
11681-
1168211558
@doc(
1168311559
_num_ddof_doc,
1168411560
desc="Return unbiased standard error of the mean over requested "

pandas/core/groupby/base.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ class OutputKey:
3636
"idxmax",
3737
"idxmin",
3838
"last",
39-
"mad",
4039
"max",
4140
"mean",
4241
"median",
@@ -86,7 +85,6 @@ def maybe_normalize_deprecated_kernels(kernel) -> Literal["bfill", "ffill"]:
8685
"pct_change",
8786
"rank",
8887
"shift",
89-
"tshift",
9088
]
9189
)
9290

0 commit comments

Comments
 (0)