Skip to content

Commit b4ff385

Browse files
authored
DEPR: Enforce expanding(center) deprecation (#48840)
1 parent c110f27 commit b4ff385

File tree

4 files changed

+5
-43
lines changed

4 files changed

+5
-43
lines changed

doc/source/whatsnew/v2.0.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ Removal of prior version deprecations/changes
150150
- Removed the ``numeric_only`` keyword from :meth:`Categorical.min` and :meth:`Categorical.max` in favor of ``skipna`` (:issue:`48821`)
151151
- Removed :func:`is_extension_type` in favor of :func:`is_extension_array_dtype` (:issue:`29457`)
152152
- Remove :meth:`DataFrameGroupBy.pad` and :meth:`DataFrameGroupBy.backfill` (:issue:`45076`)
153+
- Removed the ``center`` keyword in :meth:`DataFrame.expanding` (:issue:`20647`)
153154
- Enforced :meth:`Rolling.count` with ``min_periods=None`` to default to the size of the window (:issue:`31302`)
154155

155156
.. ---------------------------------------------------------------------------

pandas/core/generic.py

+1-13
Original file line numberDiff line numberDiff line change
@@ -12095,23 +12095,11 @@ def rolling(
1209512095
def expanding(
1209612096
self,
1209712097
min_periods: int = 1,
12098-
center: bool_t | None = None,
1209912098
axis: Axis = 0,
1210012099
method: str = "single",
1210112100
) -> Expanding:
1210212101
axis = self._get_axis_number(axis)
12103-
if center is not None:
12104-
warnings.warn(
12105-
"The `center` argument on `expanding` will be removed in the future.",
12106-
FutureWarning,
12107-
stacklevel=find_stack_level(),
12108-
)
12109-
else:
12110-
center = False
12111-
12112-
return Expanding(
12113-
self, min_periods=min_periods, center=center, axis=axis, method=method
12114-
)
12102+
return Expanding(self, min_periods=min_periods, axis=axis, method=method)
1211512103

1211612104
@final
1211712105
@doc(ExponentialMovingWindow)

pandas/core/window/expanding.py

+1-10
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,6 @@ class Expanding(RollingAndExpandingMixin):
5555
Minimum number of observations in window required to have a value;
5656
otherwise, result is ``np.nan``.
5757
58-
center : bool, default False
59-
If False, set the window labels as the right edge of the window index.
60-
61-
If True, set the window labels as the center of the window index.
62-
63-
.. deprecated:: 1.1.0
64-
6558
axis : int or str, default 0
6659
If ``0`` or ``'index'``, roll across the rows.
6760
@@ -123,21 +116,19 @@ class Expanding(RollingAndExpandingMixin):
123116
4 7.0
124117
"""
125118

126-
_attributes: list[str] = ["min_periods", "center", "axis", "method"]
119+
_attributes: list[str] = ["min_periods", "axis", "method"]
127120

128121
def __init__(
129122
self,
130123
obj: NDFrame,
131124
min_periods: int = 1,
132-
center: bool | None = None,
133125
axis: Axis = 0,
134126
method: str = "single",
135127
selection=None,
136128
) -> None:
137129
super().__init__(
138130
obj=obj,
139131
min_periods=min_periods,
140-
center=center,
141132
axis=axis,
142133
method=method,
143134
selection=selection,

pandas/tests/window/test_expanding.py

+2-20
Original file line numberDiff line numberDiff line change
@@ -23,24 +23,16 @@ def test_doc_string():
2323
df.expanding(2).sum()
2424

2525

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

3229
c = frame_or_series(range(5)).expanding
3330

3431
# valid
3532
c(min_periods=1)
36-
c(min_periods=1, center=True)
37-
c(min_periods=1, center=False)
3833

3934

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

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

52-
msg = "center must be a boolean"
53-
with pytest.raises(ValueError, match=msg):
54-
c(min_periods=1, center=w)
55-
5644

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

243231

244-
def test_center_deprecate_warning():
232+
def test_center_invalid():
245233
# GH 20647
246234
df = DataFrame()
247-
with tm.assert_produces_warning(FutureWarning):
235+
with pytest.raises(TypeError, match=".* got an unexpected keyword"):
248236
df.expanding(center=True)
249237

250-
with tm.assert_produces_warning(FutureWarning):
251-
df.expanding(center=False)
252-
253-
with tm.assert_produces_warning(None):
254-
df.expanding()
255-
256238

257239
def test_expanding_sem(frame_or_series):
258240
# GH: 26476

0 commit comments

Comments
 (0)