Skip to content

DEPR: Enforce expanding(center) deprecation #48840

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 9 commits into from
Oct 20, 2022
1 change: 1 addition & 0 deletions doc/source/whatsnew/v2.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ Removal of prior version deprecations/changes
- Disallow passing non-round floats to :class:`Timestamp` with ``unit="M"`` or ``unit="Y"`` (:issue:`47266`)
- Removed :func:`is_extension_type` in favor of :func:`is_extension_array_dtype` (:issue:`29457`)
- Remove :meth:`DataFrameGroupBy.pad` and :meth:`DataFrameGroupBy.backfill` (:issue:`45076`)
- Removed the ``center`` keyword in :meth:`DataFrame.expanding` (:issue:`20647`)
- Enforced :meth:`Rolling.count` with ``min_periods=None`` to default to the size of the window (:issue:`31302`)

.. ---------------------------------------------------------------------------
Expand Down
14 changes: 1 addition & 13 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -12095,23 +12095,11 @@ def rolling(
def expanding(
self,
min_periods: int = 1,
center: bool_t | None = None,
axis: Axis = 0,
method: str = "single",
) -> Expanding:
axis = self._get_axis_number(axis)
if center is not None:
warnings.warn(
"The `center` argument on `expanding` will be removed in the future.",
FutureWarning,
stacklevel=find_stack_level(),
)
else:
center = False

return Expanding(
self, min_periods=min_periods, center=center, axis=axis, method=method
)
return Expanding(self, min_periods=min_periods, axis=axis, method=method)

@final
@doc(ExponentialMovingWindow)
Expand Down
11 changes: 1 addition & 10 deletions pandas/core/window/expanding.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,6 @@ class Expanding(RollingAndExpandingMixin):
Minimum number of observations in window required to have a value;
otherwise, result is ``np.nan``.

center : bool, default False
If False, set the window labels as the right edge of the window index.

If True, set the window labels as the center of the window index.

.. deprecated:: 1.1.0

axis : int or str, default 0
If ``0`` or ``'index'``, roll across the rows.

Expand Down Expand Up @@ -123,21 +116,19 @@ class Expanding(RollingAndExpandingMixin):
4 7.0
"""

_attributes: list[str] = ["min_periods", "center", "axis", "method"]
_attributes: list[str] = ["min_periods", "axis", "method"]

def __init__(
self,
obj: NDFrame,
min_periods: int = 1,
center: bool | None = None,
axis: Axis = 0,
method: str = "single",
selection=None,
) -> None:
super().__init__(
obj=obj,
min_periods=min_periods,
center=center,
axis=axis,
method=method,
selection=selection,
Expand Down
22 changes: 2 additions & 20 deletions pandas/tests/window/test_expanding.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,16 @@ def test_doc_string():
df.expanding(2).sum()


@pytest.mark.filterwarnings(
"ignore:The `center` argument on `expanding` will be removed in the future"
)
def test_constructor(frame_or_series):
# GH 12669

c = frame_or_series(range(5)).expanding

# valid
c(min_periods=1)
c(min_periods=1, center=True)
c(min_periods=1, center=False)


@pytest.mark.parametrize("w", [2.0, "foo", np.array([2])])
@pytest.mark.filterwarnings(
"ignore:The `center` argument on `expanding` will be removed in the future"
)
def test_constructor_invalid(frame_or_series, w):
# not valid

Expand All @@ -49,10 +41,6 @@ def test_constructor_invalid(frame_or_series, w):
with pytest.raises(ValueError, match=msg):
c(min_periods=w)

msg = "center must be a boolean"
with pytest.raises(ValueError, match=msg):
c(min_periods=1, center=w)


@pytest.mark.parametrize("method", ["std", "mean", "sum", "max", "min", "var"])
def test_numpy_compat(method):
Expand Down Expand Up @@ -241,18 +229,12 @@ def test_iter_expanding_series(ser, expected, min_periods):
tm.assert_series_equal(actual, expected)


def test_center_deprecate_warning():
def test_center_invalid():
# GH 20647
df = DataFrame()
with tm.assert_produces_warning(FutureWarning):
with pytest.raises(TypeError, match=".* got an unexpected keyword"):
df.expanding(center=True)

with tm.assert_produces_warning(FutureWarning):
df.expanding(center=False)

with tm.assert_produces_warning(None):
df.expanding()


def test_expanding_sem(frame_or_series):
# GH: 26476
Expand Down