From 1ccc941f064f297d9cba3d5f5ba5bdaf97db22e2 Mon Sep 17 00:00:00 2001 From: arthurlw Date: Fri, 18 Apr 2025 11:54:35 -0700 Subject: [PATCH 1/5] updated ewm arguments --- pandas/core/groupby/groupby.py | 76 +++++++++++++++++++++------------- 1 file changed, 47 insertions(+), 29 deletions(-) diff --git a/pandas/core/groupby/groupby.py b/pandas/core/groupby/groupby.py index 7d58d8f867c12..402412da1cd43 100644 --- a/pandas/core/groupby/groupby.py +++ b/pandas/core/groupby/groupby.py @@ -141,6 +141,7 @@ class providing the base-class of operations. if TYPE_CHECKING: from pandas._libs.tslibs import BaseOffset + from pandas._libs.tslibs.timedeltas import Timedelta from pandas._typing import ( Any, Concatenate, @@ -3866,39 +3867,49 @@ def expanding(self, *args, **kwargs) -> ExpandingGroupby: ) @final - def ewm(self, *args, **kwargs) -> ExponentialMovingWindowGroupby: + def ewm( + self, + com: float | None = None, + span: float | None = None, + halflife: float | str | Timedelta | None = None, + alpha: float | None = None, + min_periods: int | None = 0, + adjust: bool = True, + ignore_na: bool = False, + times: np.ndarray | Series | None = None, + method: str = "single", + ) -> ExponentialMovingWindowGroupby: """ Return an ewm grouper, providing ewm functionality per group. Parameters ---------- - *args : tuple - Positional arguments passed to the EWM window constructor. - **kwargs : dict - Keyword arguments passed to the EWM window constructor, such as: - - com : float, optional - Specify decay in terms of center of mass. - ``span``, ``halflife``, and ``alpha`` are alternative ways to specify - decay. - span : float, optional - Specify decay in terms of span. - halflife : float, optional - Specify decay in terms of half-life. - alpha : float, optional - Specify smoothing factor directly. - min_periods : int, default 0 - Minimum number of observations in the window required to have a value; - otherwise, result is ``np.nan``. - adjust : bool, default True - Divide by decaying adjustment factor to account for imbalance in + com : float, optional + Specify decay in terms of center of mass. + Alternative to ``span``, ``halflife``, and ``alpha``. + + span : float, optional + Specify decay in terms of span. + + halflife : float, str, or Timedelta, optional + Specify decay in terms of half-life. + + alpha : float, optional + Specify smoothing factor directly. + + min_periods : int, default 0 + Minimum number of observations in the window required to have a value; + otherwise, result is ``np.nan``. + + adjust : bool, default True + Divide by decaying adjustment factor to account for imbalance in relative weights. - ignore_na : bool, default False - Ignore missing values when calculating weights. - times : str or array-like of datetime64, optional - Times corresponding to the observations. - axis : {0 or 'index', 1 or 'columns'}, default 0 - Axis along which the EWM function is applied. + + ignore_na : bool, default False + Ignore missing values when calculating weights. + + times : str or array-like of datetime64, optional + Times corresponding to the observations. Returns ------- @@ -3944,9 +3955,16 @@ def ewm(self, *args, **kwargs) -> ExponentialMovingWindowGroupby: return ExponentialMovingWindowGroupby( self._selected_obj, - *args, + com=com, + span=span, + halflife=halflife, + alpha=alpha, + min_periods=min_periods, + adjust=adjust, + ignore_na=ignore_na, + times=times, + method=method, _grouper=self._grouper, - **kwargs, ) @final From f75b9cc7cc4f14e5a46582bedbd6be13f4137bb4 Mon Sep 17 00:00:00 2001 From: arthurlw Date: Mon, 21 Apr 2025 17:20:46 -0700 Subject: [PATCH 2/5] added method argument to docstring --- pandas/core/groupby/groupby.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pandas/core/groupby/groupby.py b/pandas/core/groupby/groupby.py index 402412da1cd43..2e063da231c95 100644 --- a/pandas/core/groupby/groupby.py +++ b/pandas/core/groupby/groupby.py @@ -3911,6 +3911,12 @@ def ewm( times : str or array-like of datetime64, optional Times corresponding to the observations. + method : {'single', 'table'}, default 'single' + Method for computing the exponentially weighted statistics. + * ``'single'``: Calculate the statistic for each group independently. + * ``'table'``: Calculate the statistic using the entire table and then + regroup. Useful for performance but may give different results. + Returns ------- pandas.api.typing.ExponentialMovingWindowGroupby From 0279a8154f1ad2fa4709761c154fe02a61e42586 Mon Sep 17 00:00:00 2001 From: arthurlw Date: Mon, 21 Apr 2025 17:56:52 -0700 Subject: [PATCH 3/5] removed unexpected indentation --- pandas/core/groupby/groupby.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/groupby/groupby.py b/pandas/core/groupby/groupby.py index 2e063da231c95..7a151086f5558 100644 --- a/pandas/core/groupby/groupby.py +++ b/pandas/core/groupby/groupby.py @@ -3903,7 +3903,7 @@ def ewm( adjust : bool, default True Divide by decaying adjustment factor to account for imbalance in - relative weights. + relative weights. ignore_na : bool, default False Ignore missing values when calculating weights. From 51d79425e508ad69605c3d2e173d86cd711a03d3 Mon Sep 17 00:00:00 2001 From: arthurlw Date: Mon, 21 Apr 2025 18:40:55 -0700 Subject: [PATCH 4/5] updated method parameter description --- pandas/core/groupby/groupby.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/pandas/core/groupby/groupby.py b/pandas/core/groupby/groupby.py index 7a151086f5558..4856e3bbe1528 100644 --- a/pandas/core/groupby/groupby.py +++ b/pandas/core/groupby/groupby.py @@ -3912,10 +3912,9 @@ def ewm( Times corresponding to the observations. method : {'single', 'table'}, default 'single' - Method for computing the exponentially weighted statistics. - * ``'single'``: Calculate the statistic for each group independently. - * ``'table'``: Calculate the statistic using the entire table and then - regroup. Useful for performance but may give different results. + Execute the operation per group independently (``'single'``) or over the entire + object before regrouping (``'table'``). Only applicable to ``mean()``, and only + when using ``engine='numba'``. Returns ------- From 30353a34bc9633bc2db8fe42a1f578a9f4b85d92 Mon Sep 17 00:00:00 2001 From: arthurlw Date: Mon, 21 Apr 2025 18:50:31 -0700 Subject: [PATCH 5/5] precommit --- pandas/core/groupby/groupby.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pandas/core/groupby/groupby.py b/pandas/core/groupby/groupby.py index 4856e3bbe1528..fc9880ee80871 100644 --- a/pandas/core/groupby/groupby.py +++ b/pandas/core/groupby/groupby.py @@ -3912,9 +3912,9 @@ def ewm( Times corresponding to the observations. method : {'single', 'table'}, default 'single' - Execute the operation per group independently (``'single'``) or over the entire - object before regrouping (``'table'``). Only applicable to ``mean()``, and only - when using ``engine='numba'``. + Execute the operation per group independently (``'single'``) or over the + entire object before regrouping (``'table'``). Only applicable to + ``mean()``, and only when using ``engine='numba'``. Returns -------