Skip to content
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

Deprecate center on df.expanding #34887

Merged
merged 4 commits into from
Jul 14, 2020
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
3 changes: 3 additions & 0 deletions doc/source/whatsnew/v1.1.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -820,6 +820,9 @@ Deprecations
precision through the ``rtol``, and ``atol`` parameters, thus deprecating the
``check_less_precise`` parameter. (:issue:`13357`).
- :func:`DataFrame.melt` accepting a value_name that already exists is deprecated, and will be removed in a future version (:issue:`34731`)
- the ``center`` keyword in the :meth:`DataFrame.expanding` function is deprecated and will be removed in a future version (:issue:`20647`)
MBrouns marked this conversation as resolved.
Show resolved Hide resolved



.. ---------------------------------------------------------------------------

Expand Down
12 changes: 11 additions & 1 deletion pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -10501,8 +10501,18 @@ def rolling(
cls.rolling = rolling

@doc(Expanding)
def expanding(self, min_periods=1, center=False, axis=0):
def expanding(self, min_periods=1, center=None, axis=0):
MBrouns marked this conversation as resolved.
Show resolved Hide resolved
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=2,
)
else:
center = False

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

cls.expanding = expanding
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/window/expanding.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class Expanding(_Rolling_and_Expanding):

_attributes = ["min_periods", "center", "axis"]

def __init__(self, obj, min_periods=1, center=False, axis=0, **kwargs):
def __init__(self, obj, min_periods=1, center=None, axis=0, **kwargs):
super().__init__(obj=obj, min_periods=min_periods, center=center, axis=axis)

@property
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ def test_expanding_corr_pairwise(frame):
ids=["sum", "mean", "max", "min"],
)
def test_expanding_func(func, static_comp, has_min_periods, series, frame, nan_locs):
def expanding_func(x, min_periods=1, center=False, axis=0):
exp = x.expanding(min_periods=min_periods, center=center, axis=axis)
def expanding_func(x, min_periods=1, axis=0):
exp = x.expanding(min_periods=min_periods, axis=axis)
return getattr(exp, func)()

_check_expanding(
Expand Down Expand Up @@ -166,7 +166,7 @@ def test_expanding_apply_consistency(

with warnings.catch_warnings():
warnings.filterwarnings(
"ignore", message=".*(empty slice|0 for slice).*", category=RuntimeWarning,
"ignore", message=".*(empty slice|0 for slice).*", category=RuntimeWarning
)
# test consistency between expanding_xyz() and either (a)
# expanding_apply of Series.xyz(), or (b) expanding_apply of
Expand Down Expand Up @@ -267,7 +267,7 @@ def test_expanding_consistency(consistency_data, min_periods):
# with empty/0-length Series/DataFrames
with warnings.catch_warnings():
warnings.filterwarnings(
"ignore", message=".*(empty slice|0 for slice).*", category=RuntimeWarning,
"ignore", message=".*(empty slice|0 for slice).*", category=RuntimeWarning
)

# test consistency between different expanding_* moments
Expand Down Expand Up @@ -454,7 +454,7 @@ def test_expanding_cov_pairwise_diff_length():
def test_expanding_corr_pairwise_diff_length():
# GH 7512
df1 = DataFrame(
[[1, 2], [3, 2], [3, 4]], columns=["A", "B"], index=Index(range(3), name="bar"),
[[1, 2], [3, 2], [3, 4]], columns=["A", "B"], index=Index(range(3), name="bar")
)
df1a = DataFrame(
[[1, 2], [3, 4]], index=Index([0, 2], name="bar"), columns=["A", "B"]
Expand Down
11 changes: 2 additions & 9 deletions pandas/tests/window/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,7 @@ def test_agg():

with pytest.raises(SpecificationError, match=msg):
r.aggregate(
{
"A": {"mean": "mean", "sum": "sum"},
"B": {"mean2": "mean", "sum2": "sum"},
}
{"A": {"mean": "mean", "sum": "sum"}, "B": {"mean2": "mean", "sum2": "sum"}}
)

result = r.aggregate({"A": ["mean", "std"], "B": ["mean", "std"]})
Expand Down Expand Up @@ -191,11 +188,7 @@ def test_count_nonnumeric_types():
"dt_nat",
"periods_nat",
]
dt_nat_col = [
Timestamp("20170101"),
Timestamp("20170203"),
Timestamp(None),
]
dt_nat_col = [Timestamp("20170101"), Timestamp("20170203"), Timestamp(None)]

df = DataFrame(
{
Expand Down
16 changes: 16 additions & 0 deletions pandas/tests/window/test_expanding.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ 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(which):
# GH 12669

Expand Down Expand Up @@ -213,3 +216,16 @@ def test_iter_expanding_series(ser, expected, min_periods):

for (expected, actual) in zip(expected, ser.expanding(min_periods)):
tm.assert_series_equal(actual, expected)


def test_center_deprecate_warning():
# GH 20647
df = pd.DataFrame()
with tm.assert_produces_warning(FutureWarning):
df.expanding(center=True)

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

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