Skip to content

DEPR: Enforce deprecation of mad and tshift #49252

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

Merged
merged 4 commits into from
Oct 23, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 1 addition & 4 deletions asv_bench/benchmarks/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
"pct_change",
"min",
"var",
"mad",
"describe",
"std",
"quantile",
Expand All @@ -52,7 +51,6 @@
"cummax",
"pct_change",
"var",
"mad",
"describe",
"std",
},
Expand Down Expand Up @@ -437,7 +435,6 @@ class GroupByMethods:
"first",
"head",
"last",
"mad",
"max",
"min",
"median",
Expand Down Expand Up @@ -483,7 +480,7 @@ def setup(self, dtype, method, application, ncols):

if method == "describe":
ngroups = 20
elif method in ["mad", "skew"]:
elif method == "skew":
ngroups = 100
else:
ngroups = 1000
Expand Down
5 changes: 1 addition & 4 deletions asv_bench/benchmarks/stat_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import pandas as pd

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


class FrameOps:
Expand All @@ -11,9 +11,6 @@ class FrameOps:
param_names = ["op", "dtype", "axis"]

def setup(self, op, dtype, axis):
if op == "mad" and dtype == "Int64":
# GH-33036, GH#33600
raise NotImplementedError
values = np.random.randn(100000, 4)
if dtype == "Int64":
values = values.astype(int)
Expand Down
6 changes: 0 additions & 6 deletions doc/redirects.csv
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@ generated/pandas.core.groupby.DataFrameGroupBy.filter,../reference/api/pandas.co
generated/pandas.core.groupby.DataFrameGroupBy.hist,../reference/api/pandas.core.groupby.DataFrameGroupBy.hist
generated/pandas.core.groupby.DataFrameGroupBy.idxmax,../reference/api/pandas.core.groupby.DataFrameGroupBy.idxmax
generated/pandas.core.groupby.DataFrameGroupBy.idxmin,../reference/api/pandas.core.groupby.DataFrameGroupBy.idxmin
generated/pandas.core.groupby.DataFrameGroupBy.mad,../reference/api/pandas.core.groupby.DataFrameGroupBy.mad
generated/pandas.core.groupby.DataFrameGroupBy.pct_change,../reference/api/pandas.core.groupby.DataFrameGroupBy.pct_change
generated/pandas.core.groupby.DataFrameGroupBy.plot,../reference/api/pandas.core.groupby.DataFrameGroupBy.plot
generated/pandas.core.groupby.DataFrameGroupBy.quantile,../reference/api/pandas.core.groupby.DataFrameGroupBy.quantile
Expand All @@ -196,7 +195,6 @@ generated/pandas.core.groupby.DataFrameGroupBy.shift,../reference/api/pandas.cor
generated/pandas.core.groupby.DataFrameGroupBy.size,../reference/api/pandas.core.groupby.DataFrameGroupBy.size
generated/pandas.core.groupby.DataFrameGroupBy.skew,../reference/api/pandas.core.groupby.DataFrameGroupBy.skew
generated/pandas.core.groupby.DataFrameGroupBy.take,../reference/api/pandas.core.groupby.DataFrameGroupBy.take
generated/pandas.core.groupby.DataFrameGroupBy.tshift,../reference/api/pandas.core.groupby.DataFrameGroupBy.tshift
generated/pandas.core.groupby.GroupBy.agg,../reference/api/pandas.core.groupby.GroupBy.agg
generated/pandas.core.groupby.GroupBy.aggregate,../reference/api/pandas.core.groupby.GroupBy.aggregate
generated/pandas.core.groupby.GroupBy.all,../reference/api/pandas.core.groupby.GroupBy.all
Expand Down Expand Up @@ -415,7 +413,6 @@ generated/pandas.DataFrame.le,../reference/api/pandas.DataFrame.le
generated/pandas.DataFrame.loc,../reference/api/pandas.DataFrame.loc
generated/pandas.DataFrame.lookup,../reference/api/pandas.DataFrame.lookup
generated/pandas.DataFrame.lt,../reference/api/pandas.DataFrame.lt
generated/pandas.DataFrame.mad,../reference/api/pandas.DataFrame.mad
generated/pandas.DataFrame.mask,../reference/api/pandas.DataFrame.mask
generated/pandas.DataFrame.max,../reference/api/pandas.DataFrame.max
generated/pandas.DataFrame.mean,../reference/api/pandas.DataFrame.mean
Expand Down Expand Up @@ -528,7 +525,6 @@ generated/pandas.DataFrame.transform,../reference/api/pandas.DataFrame.transform
generated/pandas.DataFrame.transpose,../reference/api/pandas.DataFrame.transpose
generated/pandas.DataFrame.truediv,../reference/api/pandas.DataFrame.truediv
generated/pandas.DataFrame.truncate,../reference/api/pandas.DataFrame.truncate
generated/pandas.DataFrame.tshift,../reference/api/pandas.DataFrame.tshift
generated/pandas.DataFrame.tz_convert,../reference/api/pandas.DataFrame.tz_convert
generated/pandas.DataFrame.tz_localize,../reference/api/pandas.DataFrame.tz_localize
generated/pandas.DataFrame.unstack,../reference/api/pandas.DataFrame.unstack
Expand Down Expand Up @@ -1097,7 +1093,6 @@ generated/pandas.Series.last_valid_index,../reference/api/pandas.Series.last_val
generated/pandas.Series.le,../reference/api/pandas.Series.le
generated/pandas.Series.loc,../reference/api/pandas.Series.loc
generated/pandas.Series.lt,../reference/api/pandas.Series.lt
generated/pandas.Series.mad,../reference/api/pandas.Series.mad
generated/pandas.Series.map,../reference/api/pandas.Series.map
generated/pandas.Series.mask,../reference/api/pandas.Series.mask
generated/pandas.Series.max,../reference/api/pandas.Series.max
Expand Down Expand Up @@ -1266,7 +1261,6 @@ generated/pandas.Series.transform,../reference/api/pandas.Series.transform
generated/pandas.Series.transpose,../reference/api/pandas.Series.transpose
generated/pandas.Series.truediv,../reference/api/pandas.Series.truediv
generated/pandas.Series.truncate,../reference/api/pandas.Series.truncate
generated/pandas.Series.tshift,../reference/api/pandas.Series.tshift
generated/pandas.Series.tz_convert,../reference/api/pandas.Series.tz_convert
generated/pandas.Series.tz_localize,../reference/api/pandas.Series.tz_localize
generated/pandas.Series.unique,../reference/api/pandas.Series.unique
Expand Down
2 changes: 0 additions & 2 deletions doc/source/reference/frame.rst
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ Computations / descriptive stats
DataFrame.eval
DataFrame.kurt
DataFrame.kurtosis
DataFrame.mad
DataFrame.max
DataFrame.mean
DataFrame.median
Expand Down Expand Up @@ -268,7 +267,6 @@ Time Series-related
DataFrame.asof
DataFrame.shift
DataFrame.slice_shift
DataFrame.tshift
DataFrame.first_valid_index
DataFrame.last_valid_index
DataFrame.resample
Expand Down
4 changes: 0 additions & 4 deletions doc/source/reference/groupby.rst
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ Function application
DataFrameGroupBy.idxmax
DataFrameGroupBy.idxmin
DataFrameGroupBy.last
DataFrameGroupBy.mad
DataFrameGroupBy.max
DataFrameGroupBy.mean
DataFrameGroupBy.median
Expand All @@ -108,7 +107,6 @@ Function application
DataFrameGroupBy.var
DataFrameGroupBy.tail
DataFrameGroupBy.take
DataFrameGroupBy.tshift
DataFrameGroupBy.value_counts

``SeriesGroupBy`` computations / descriptive stats
Expand Down Expand Up @@ -138,7 +136,6 @@ Function application
SeriesGroupBy.idxmin
SeriesGroupBy.is_monotonic_increasing
SeriesGroupBy.is_monotonic_decreasing
SeriesGroupBy.mad
SeriesGroupBy.max
SeriesGroupBy.mean
SeriesGroupBy.median
Expand All @@ -165,7 +162,6 @@ Function application
SeriesGroupBy.var
SeriesGroupBy.tail
SeriesGroupBy.take
SeriesGroupBy.tshift
SeriesGroupBy.value_counts

Plotting and visualization
Expand Down
2 changes: 0 additions & 2 deletions doc/source/reference/series.rst
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ Computations / descriptive stats
Series.diff
Series.factorize
Series.kurt
Series.mad
Series.max
Series.mean
Series.median
Expand Down Expand Up @@ -269,7 +268,6 @@ Time Series-related
Series.tz_localize
Series.at_time
Series.between_time
Series.tshift
Series.slice_shift

Accessors
Expand Down
1 change: 0 additions & 1 deletion doc/source/user_guide/basics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,6 @@ optional ``level`` parameter which applies only if the object has a
``count``, Number of non-NA observations
``sum``, Sum of values
``mean``, Mean of values
``mad``, Mean absolute deviation
``median``, Arithmetic median of values
``min``, Minimum
``max``, Maximum
Expand Down
3 changes: 2 additions & 1 deletion doc/source/whatsnew/v2.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,8 @@ Removal of prior version deprecations/changes
- Removed ``pandas.SparseSeries`` and ``pandas.SparseDataFrame`` (:issue:`30642`)
- Enforced disallowing a string column label into ``times`` in :meth:`DataFrame.ewm` (:issue:`43265`)
- Enforced :meth:`Rolling.count` with ``min_periods=None`` to default to the size of the window (:issue:`31302`)
-
- Removed the deprecated method ``mad`` from pandas classes (:issue:`11787`)
- Removed the deprecated method ``tshift`` from pandas classes (:issue:`11631`)

.. ---------------------------------------------------------------------------
.. _whatsnew_200.performance:
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ def apply_str(self) -> DataFrame | Series:
sig = inspect.getfullargspec(func)
arg_names = (*sig.args, *sig.kwonlyargs)
if self.axis != 0 and (
"axis" not in arg_names or f in ("corrwith", "mad", "skew")
"axis" not in arg_names or f in ("corrwith", "skew")
):
raise ValueError(f"Operation {f} does not support axis=1")
elif "axis" in arg_names:
Expand Down
126 changes: 1 addition & 125 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ class NDFrame(PandasObject, indexing.IndexingMixin):
_internal_names_set: set[str] = set(_internal_names)
_accessors: set[str] = set()
_hidden_attrs: frozenset[str] = frozenset(
["_AXIS_NAMES", "_AXIS_NUMBERS", "get_values", "tshift"]
["_AXIS_NAMES", "_AXIS_NUMBERS", "get_values"]
)
_metadata: list[str] = []
_is_copy: weakref.ReferenceType[NDFrame] | None = None
Expand Down Expand Up @@ -10122,8 +10122,6 @@ def shift(
Index.shift : Shift values of Index.
DatetimeIndex.shift : Shift values of DatetimeIndex.
PeriodIndex.shift : Shift values of PeriodIndex.
tshift : Shift the time index, using the index's frequency if
available.

Examples
--------
Expand Down Expand Up @@ -10272,49 +10270,6 @@ def slice_shift(self: NDFrameT, periods: int = 1, axis: Axis = 0) -> NDFrameT:
new_obj = new_obj.set_axis(shifted_axis, axis=axis, copy=False)
return new_obj.__finalize__(self, method="slice_shift")

@final
def tshift(self: NDFrameT, periods: int = 1, freq=None, axis: Axis = 0) -> NDFrameT:
"""
Shift the time index, using the index's frequency if available.

.. deprecated:: 1.1.0
Use `shift` instead.

Parameters
----------
periods : int
Number of periods to move, can be positive or negative.
freq : DateOffset, timedelta, or str, default None
Increment to use from the tseries module
or time rule expressed as a string (e.g. 'EOM').
axis : {0 or ‘index’, 1 or ‘columns’, None}, default 0
Corresponds to the axis that contains the Index.
For `Series` this parameter is unused and defaults to 0.

Returns
-------
shifted : Series/DataFrame

Notes
-----
If freq is not specified then tries to use the freq or inferred_freq
attributes of the index. If neither of those attributes exist, a
ValueError is thrown
"""
warnings.warn(
(
"tshift is deprecated and will be removed in a future version. "
"Please use shift instead."
),
FutureWarning,
stacklevel=find_stack_level(),
)

if freq is None:
freq = "infer"

return self.shift(periods, freq, axis)

def truncate(
self: NDFrameT,
before=None,
Expand Down Expand Up @@ -11544,70 +11499,6 @@ def prod(

product = prod

def mad(
self,
axis: Axis | None = None,
skipna: bool_t = True,
level: Level | None = None,
) -> Series | float:
"""
{desc}

.. deprecated:: 1.5.0
mad is deprecated.

Parameters
----------
axis : {axis_descr}
Axis for the function to be applied on.
For `Series` this parameter is unused and defaults to 0.
skipna : bool, default True
Exclude NA/null values when computing the result.
level : int or level name, default None
If the axis is a MultiIndex (hierarchical), count along a
particular level, collapsing into a {name1}.

Returns
-------
{name1} or {name2} (if level specified)\
{see_also}\
{examples}
"""
msg = (
"The 'mad' method is deprecated and will be removed in a future version. "
"To compute the same result, you may do `(df - df.mean()).abs().mean()`."
)
warnings.warn(msg, FutureWarning, stacklevel=find_stack_level())

if not is_bool(skipna):
warnings.warn(
"Passing None for skipna is deprecated and will raise in a future"
"version. Pass True instead. Only boolean values will be allowed "
"in the future.",
FutureWarning,
stacklevel=find_stack_level(),
)
skipna = True
if axis is None:
axis = self._stat_axis_number
if level is not None:
warnings.warn(
"Using the level keyword in DataFrame and Series aggregations is "
"deprecated and will be removed in a future version. Use groupby "
"instead. df.mad(level=1) should use df.groupby(level=1).mad()",
FutureWarning,
stacklevel=find_stack_level(),
)
return self._agg_by_level("mad", axis=axis, level=level, skipna=skipna)

data = self._get_numeric_data()
if axis == 0:
# error: Unsupported operand types for - ("NDFrame" and "float")
demeaned = data - data.mean(axis=0) # type: ignore[operator]
else:
demeaned = data.sub(data.mean(axis=1), axis=0)
return np.abs(demeaned).mean(axis=axis, skipna=skipna)

@classmethod
def _add_numeric_operations(cls) -> None:
"""
Expand Down Expand Up @@ -11664,21 +11555,6 @@ def all(

setattr(cls, "all", all)

@doc(
NDFrame.mad.__doc__,
desc="Return the mean absolute deviation of the values "
"over the requested axis.",
name1=name1,
name2=name2,
axis_descr=axis_descr,
see_also="",
examples="",
)
def mad(self, axis: Axis | None = None, skipna: bool_t = True, level=None):
return NDFrame.mad(self, axis, skipna, level)

setattr(cls, "mad", mad)

@doc(
_num_ddof_doc,
desc="Return unbiased standard error of the mean over requested "
Expand Down
2 changes: 0 additions & 2 deletions pandas/core/groupby/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ class OutputKey:
"idxmax",
"idxmin",
"last",
"mad",
"max",
"mean",
"median",
Expand Down Expand Up @@ -86,7 +85,6 @@ def maybe_normalize_deprecated_kernels(kernel) -> Literal["bfill", "ffill"]:
"pct_change",
"rank",
"shift",
"tshift",
]
)

Expand Down
Loading