Skip to content

Commit 31759fa

Browse files
authored
DEPR: Passing in a string column label for DataFrame.ewm(times=...) (#43265)
1 parent 5c81ac4 commit 31759fa

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

doc/source/whatsnew/v1.4.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ Other Deprecations
274274
- Deprecated dropping of nuisance columns in :class:`Rolling`, :class:`Expanding`, and :class:`EWM` aggregations (:issue:`42738`)
275275
- Deprecated :meth:`Index.reindex` with a non-unique index (:issue:`42568`)
276276
- Deprecated :meth:`.Styler.render` in favour of :meth:`.Styler.to_html` (:issue:`42140`)
277+
- Deprecated passing in a string column label into ``times`` in :meth:`DataFrame.ewm` (:issue:`43265`)
277278

278279
.. ---------------------------------------------------------------------------
279280

pandas/core/window/ewm.py

+10
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
from pandas.compat.numpy import function as nv
2323
from pandas.util._decorators import doc
24+
from pandas.util._exceptions import find_stack_level
2425

2526
from pandas.core.dtypes.common import is_datetime64_ns_dtype
2627
from pandas.core.dtypes.missing import isna
@@ -315,6 +316,15 @@ def __init__(
315316
if not self.adjust:
316317
raise NotImplementedError("times is not supported with adjust=False.")
317318
if isinstance(self.times, str):
319+
warnings.warn(
320+
(
321+
"Specifying times as a string column label is deprecated "
322+
"and will be removed in a future version. Pass the column "
323+
"into times instead."
324+
),
325+
FutureWarning,
326+
stacklevel=find_stack_level(),
327+
)
318328
self.times = self._selected_obj[self.times]
319329
if not is_datetime64_ns_dtype(self.times):
320330
raise ValueError("times must be datetime64[ns] dtype.")

pandas/tests/window/test_ewm.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ def test_ewma_halflife_without_times(halflife_with_times):
107107
np.arange(10).astype("datetime64[D]").astype("datetime64[ns]"),
108108
date_range("2000", freq="D", periods=10),
109109
date_range("2000", freq="D", periods=10).tz_localize("UTC"),
110-
"time_col",
111110
],
112111
)
113112
@pytest.mark.parametrize("min_periods", [0, 2])
@@ -231,3 +230,14 @@ def test_float_dtype_ewma(func, expected, float_numpy_dtype):
231230
result = getattr(e, func)()
232231

233232
tm.assert_frame_equal(result, expected)
233+
234+
235+
def test_times_string_col_deprecated():
236+
# GH 43265
237+
data = np.arange(10.0)
238+
data[::2] = np.nan
239+
df = DataFrame({"A": data, "time_col": date_range("2000", freq="D", periods=10)})
240+
with tm.assert_produces_warning(FutureWarning, match="Specifying times"):
241+
result = df.ewm(halflife="1 day", min_periods=0, times="time_col").mean()
242+
expected = df.ewm(halflife=1.0, min_periods=0).mean()
243+
tm.assert_frame_equal(result, expected)

0 commit comments

Comments
 (0)