diff --git a/doc/source/whatsnew/v2.0.0.rst b/doc/source/whatsnew/v2.0.0.rst index e57ba92267855..a2a0812429050 100644 --- a/doc/source/whatsnew/v2.0.0.rst +++ b/doc/source/whatsnew/v2.0.0.rst @@ -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`) .. --------------------------------------------------------------------------- diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 4f3c908817ac7..78beeb5a58dbb 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -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) diff --git a/pandas/core/window/expanding.py b/pandas/core/window/expanding.py index e997ffe1ec132..621f1ae18080d 100644 --- a/pandas/core/window/expanding.py +++ b/pandas/core/window/expanding.py @@ -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. @@ -123,13 +116,12 @@ 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, @@ -137,7 +129,6 @@ def __init__( super().__init__( obj=obj, min_periods=min_periods, - center=center, axis=axis, method=method, selection=selection, diff --git a/pandas/tests/window/test_expanding.py b/pandas/tests/window/test_expanding.py index a12997018052d..8417c6dd8419c 100644 --- a/pandas/tests/window/test_expanding.py +++ b/pandas/tests/window/test_expanding.py @@ -23,9 +23,6 @@ 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 @@ -33,14 +30,9 @@ def test_constructor(frame_or_series): # 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 @@ -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): @@ -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