Skip to content

DOC: Updated groupby.ewm arguments #61334

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 5 commits into from
Apr 22, 2025
Merged
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
83 changes: 53 additions & 30 deletions pandas/core/groupby/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -3866,39 +3867,54 @@ 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
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.
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.

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'``.

Returns
-------
Expand Down Expand Up @@ -3944,9 +3960,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
Expand Down
Loading