From e6f5f16c87dddfff8cd6aa101d654d506a013d9b Mon Sep 17 00:00:00 2001 From: Matthew Roeschke Date: Sat, 16 Jan 2021 17:48:26 -0800 Subject: [PATCH 1/4] DEPR: EWM.vol --- doc/source/whatsnew/v1.3.0.rst | 1 + pandas/core/window/ewm.py | 12 +++++++++++- pandas/tests/window/moments/test_moments_ewm.py | 6 +++--- pandas/tests/window/test_ewm.py | 8 ++++++++ 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/doc/source/whatsnew/v1.3.0.rst b/doc/source/whatsnew/v1.3.0.rst index ab00b749d5725..0cd07ca88a371 100644 --- a/doc/source/whatsnew/v1.3.0.rst +++ b/doc/source/whatsnew/v1.3.0.rst @@ -191,6 +191,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:``) - .. --------------------------------------------------------------------------- diff --git a/pandas/core/window/ewm.py b/pandas/core/window/ewm.py index 670fdc011bd96..4ba15345120ca 100644 --- a/pandas/core/window/ewm.py +++ b/pandas/core/window/ewm.py @@ -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 @@ -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) diff --git a/pandas/tests/window/moments/test_moments_ewm.py b/pandas/tests/window/moments/test_moments_ewm.py index 70706c027a21e..e44c98bbd22cb 100644 --- a/pandas/tests/window/moments/test_moments_ewm.py +++ b/pandas/tests/window/moments/test_moments_ewm.py @@ -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) @@ -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() @@ -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])) diff --git a/pandas/tests/window/test_ewm.py b/pandas/tests/window/test_ewm.py index 6b57d2f55e4ff..9c1d23fe6e7a6 100644 --- a/pandas/tests/window/test_ewm.py +++ b/pandas/tests/window/test_ewm.py @@ -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) From c83b7705b91a247965d051bd7b48ec54d9355a1d Mon Sep 17 00:00:00 2001 From: Matthew Roeschke Date: Sat, 16 Jan 2021 17:51:06 -0800 Subject: [PATCH 2/4] Add issue number --- doc/source/whatsnew/v1.3.0.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v1.3.0.rst b/doc/source/whatsnew/v1.3.0.rst index 0cd07ca88a371..93d766cee8eed 100644 --- a/doc/source/whatsnew/v1.3.0.rst +++ b/doc/source/whatsnew/v1.3.0.rst @@ -191,7 +191,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:``) +- Deprecated :meth:`core.window.ewm.ExponentialMovingWindow.vol` (:issue:`39220`) - .. --------------------------------------------------------------------------- From 985965a76a3f0276ba7ad5e52a78c199ee181167 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke Date: Sat, 16 Jan 2021 19:40:46 -0800 Subject: [PATCH 3/4] Fix some tests --- pandas/tests/window/moments/test_moments_ewm.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/tests/window/moments/test_moments_ewm.py b/pandas/tests/window/moments/test_moments_ewm.py index e44c98bbd22cb..15d37152df350 100644 --- a/pandas/tests/window/moments/test_moments_ewm.py +++ b/pandas/tests/window/moments/test_moments_ewm.py @@ -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) From 903bddeb54ad3202615bc64c8d1640841c2c4b44 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke Date: Sun, 17 Jan 2021 10:41:16 -0800 Subject: [PATCH 4/4] change vol to std --- pandas/tests/window/moments/test_moments_ewm.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/window/moments/test_moments_ewm.py b/pandas/tests/window/moments/test_moments_ewm.py index 15d37152df350..a365321101e81 100644 --- a/pandas/tests/window/moments/test_moments_ewm.py +++ b/pandas/tests/window/moments/test_moments_ewm.py @@ -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)