Skip to content

Commit 4785993

Browse files
authored
DEPR: EWM.vol (#39220)
1 parent edbd450 commit 4785993

File tree

4 files changed

+26
-7
lines changed

4 files changed

+26
-7
lines changed

doc/source/whatsnew/v1.3.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ Deprecations
192192
- 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`)
193193
- Deprecated :attr:`Rolling.win_type` returning ``"freq"`` (:issue:`38963`)
194194
- Deprecated :attr:`Rolling.is_datetimelike` (:issue:`38963`)
195+
- Deprecated :meth:`core.window.ewm.ExponentialMovingWindow.vol` (:issue:`39220`)
195196
-
196197

197198
.. ---------------------------------------------------------------------------

pandas/core/window/ewm.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from functools import partial
55
from textwrap import dedent
66
from typing import TYPE_CHECKING, Optional, Union
7+
import warnings
78

89
import numpy as np
910

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

363-
vol = std
364+
def vol(self, bias: bool = False, *args, **kwargs):
365+
warnings.warn(
366+
(
367+
"vol is deprecated will be removed in a future version. "
368+
"Use std instead."
369+
),
370+
FutureWarning,
371+
stacklevel=2,
372+
)
373+
return self.std(bias, *args, **kwargs)
364374

365375
@Substitution(name="ewm", func_name="var")
366376
@Appender(_doc_template)

pandas/tests/window/moments/test_moments_ewm.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
import pandas._testing as tm
66

77

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

1313

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

302302

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

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

311311

312312
@pytest.mark.parametrize("min_periods", [0, 1])
313-
@pytest.mark.parametrize("name", ["mean", "var", "vol"])
313+
@pytest.mark.parametrize("name", ["mean", "var", "std"])
314314
def test_ew_min_periods(min_periods, name):
315315
# excluding NaNs correctly
316316
arr = np.random.randn(50)
@@ -329,7 +329,7 @@ def test_ew_min_periods(min_periods, name):
329329
assert result[:10].isna().all()
330330
assert not result[10:].isna().any()
331331
else:
332-
# ewm.std, ewm.vol, ewm.var (with bias=False) require at least
332+
# ewm.std, ewm.var (with bias=False) require at least
333333
# two values
334334
assert result[:11].isna().all()
335335
assert not result[11:].isna().any()
@@ -343,7 +343,7 @@ def test_ew_min_periods(min_periods, name):
343343
if name == "mean":
344344
tm.assert_series_equal(result, Series([1.0]))
345345
else:
346-
# ewm.std, ewm.vol, ewm.var with bias=False require at least
346+
# ewm.std, ewm.var with bias=False require at least
347347
# two values
348348
tm.assert_series_equal(result, Series([np.NaN]))
349349

pandas/tests/window/test_ewm.py

+8
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,11 @@ def test_ewm_with_nat_raises(halflife_with_times):
135135
times = DatetimeIndex(["NaT"])
136136
with pytest.raises(ValueError, match="Cannot convert NaT values to integer"):
137137
ser.ewm(com=0.1, halflife=halflife_with_times, times=times)
138+
139+
140+
def test_ewm_vol_deprecated():
141+
ser = Series(range(1))
142+
with tm.assert_produces_warning(FutureWarning):
143+
result = ser.ewm(com=0.1).vol()
144+
expected = ser.ewm(com=0.1).std()
145+
tm.assert_series_equal(result, expected)

0 commit comments

Comments
 (0)