Skip to content

DEPR: EWM.vol #39220

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 6 commits into from
Jan 19, 2021
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
1 change: 1 addition & 0 deletions doc/source/whatsnew/v1.3.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ Deprecations
- Deprecated comparison of :class:`Timestamp` object with ``datetime.date`` objects. Instead of e.g. ``ts <= mydate`` use ``ts <= pd.Timestamp(mydate)`` or ``ts.date() <= mydate`` (:issue:`36131`)
- Deprecated :attr:`Rolling.win_type` returning ``"freq"`` (:issue:`38963`)
- Deprecated :attr:`Rolling.is_datetimelike` (:issue:`38963`)
- Deprecated :meth:`core.window.ewm.ExponentialMovingWindow.vol` (:issue:`39220`)
-

.. ---------------------------------------------------------------------------
Expand Down
12 changes: 11 additions & 1 deletion pandas/core/window/ewm.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from functools import partial
from textwrap import dedent
from typing import TYPE_CHECKING, Optional, Union
import warnings

import numpy as np

Expand Down Expand Up @@ -360,7 +361,16 @@ def std(self, bias: bool = False, *args, **kwargs):
nv.validate_window_func("std", args, kwargs)
return zsqrt(self.var(bias=bias, **kwargs))

vol = std
def vol(self, bias: bool = False, *args, **kwargs):
warnings.warn(
(
"vol is deprecated will be removed in a future version. "
"Use std instead."
),
FutureWarning,
stacklevel=2,
)
return self.std(bias, *args, **kwargs)

@Substitution(name="ewm", func_name="var")
@Appender(_doc_template)
Expand Down
12 changes: 6 additions & 6 deletions pandas/tests/window/moments/test_moments_ewm.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
import pandas._testing as tm


@pytest.mark.parametrize("name", ["var", "vol", "mean"])
@pytest.mark.parametrize("name", ["var", "std", "mean"])
def test_ewma_series(series, name):
series_result = getattr(series.ewm(com=10), name)()
assert isinstance(series_result, Series)


@pytest.mark.parametrize("name", ["var", "vol", "mean"])
@pytest.mark.parametrize("name", ["var", "std", "mean"])
def test_ewma_frame(frame, name):
frame_result = getattr(frame.ewm(com=10), name)()
assert isinstance(frame_result, DataFrame)
Expand Down Expand Up @@ -300,7 +300,7 @@ def test_ewm_domain_checks():
s.ewm(alpha=1.1)


@pytest.mark.parametrize("method", ["mean", "vol", "var"])
@pytest.mark.parametrize("method", ["mean", "std", "var"])
def test_ew_empty_series(method):
vals = Series([], dtype=np.float64)

Expand All @@ -310,7 +310,7 @@ def test_ew_empty_series(method):


@pytest.mark.parametrize("min_periods", [0, 1])
@pytest.mark.parametrize("name", ["mean", "var", "vol"])
@pytest.mark.parametrize("name", ["mean", "var", "std"])
def test_ew_min_periods(min_periods, name):
# excluding NaNs correctly
arr = np.random.randn(50)
Expand All @@ -329,7 +329,7 @@ def test_ew_min_periods(min_periods, name):
assert result[:10].isna().all()
assert not result[10:].isna().any()
else:
# ewm.std, ewm.vol, ewm.var (with bias=False) require at least
# ewm.std, ewm.var (with bias=False) require at least
# two values
assert result[:11].isna().all()
assert not result[11:].isna().any()
Expand All @@ -343,7 +343,7 @@ def test_ew_min_periods(min_periods, name):
if name == "mean":
tm.assert_series_equal(result, Series([1.0]))
else:
# ewm.std, ewm.vol, ewm.var with bias=False require at least
# ewm.std, ewm.var with bias=False require at least
# two values
tm.assert_series_equal(result, Series([np.NaN]))

Expand Down
8 changes: 8 additions & 0 deletions pandas/tests/window/test_ewm.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,11 @@ def test_ewm_with_nat_raises(halflife_with_times):
times = DatetimeIndex(["NaT"])
with pytest.raises(ValueError, match="Cannot convert NaT values to integer"):
ser.ewm(com=0.1, halflife=halflife_with_times, times=times)


def test_ewm_vol_deprecated():
ser = Series(range(1))
with tm.assert_produces_warning(FutureWarning):
result = ser.ewm(com=0.1).vol()
expected = ser.ewm(com=0.1).std()
tm.assert_series_equal(result, expected)