Skip to content

BUG: ExponentialMovingWindow.agg/aggregate fails when passing a callable #63855

@loicdiridollou

Description

@loicdiridollou

Pandas version checks

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • I have confirmed this bug exists on the main branch of pandas.

Reproducible Example

import numpy as np
from pandas import DataFrame

df = DataFrame({"A": range(4, 8), "B": range(4)})

df.ewm(1).aggregate(sum)  # fails
df.ewm(1).aggregate("sum") # works
df.ewm(1).aggregate(np.sum) # fails

Issue Description

ExponentialMovingWindow.agg/aggregate fails when using a function (strings are fine).
Seems like there is an issue in how the aggregate call is wired, rolling does not suffer from the same issue (but any ExponentialGroupBy and alike will).
The traceback is the following:

  File "<python-input-15>", line 1, in <module>
    df.ewm(1).aggregate(np.sum) # fails
    ~~~~~~~~~~~~~~~~~~~^^^^^^^^
  File "/Users/loic.diridollou/Documents/Code/pandas-stubs/gh1641_pandas_30/.venv/lib/python3.14/site-packages/pandas/core/window/ewm.py", line 524, in aggregate
    return super().aggregate(func, *args, **kwargs)
           ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/loic.diridollou/Documents/Code/pandas-stubs/gh1641_pandas_30/.venv/lib/python3.14/site-packages/pandas/core/window/rolling.py", line 654, in aggregate
    return self.apply(func, raw=False, args=args, kwargs=kwargs)
           ^^^^^^^^^^
  File "/Users/loic.diridollou/Documents/Code/pandas-stubs/gh1641_pandas_30/.venv/lib/python3.14/site-packages/pandas/core/window/rolling.py", line 305, in __getattr__
    raise AttributeError(
        f"'{type(self).__name__}' object has no attribute '{attr}'"
    )
AttributeError: 'ExponentialMovingWindow' object has no attribute 'apply'. Did you mean: '_apply'?

Expected Behavior

The use of a callable should not fail since other functions passed as string (mean, cov, corr, sum, ...). are working fine.

Installed Versions

Details

Replace this line with the output of pd.show_versions()

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugNeeds TriageIssue that has not been reviewed by a pandas team member

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions