The following code fails:

import numpy as np
import pandas as pd

df = pd.DataFrame(np.random.normal(size=(100, 10)))
df.ewm(alpha=0.1).agg(lambda x: x)

Below the traceback

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-69-c018ca7d52b8> in <module>
----> 1 df.ewm(alpha=0.1).agg(lambda x: x)

c:\dev\projects\weedget\venv\lib\site-packages\pandas\core\window\ewm.py in aggregate(self, func, *args, **kwargs)
    316     )
    317     def aggregate(self, func, *args, **kwargs):
--> 318         return super().aggregate(func, *args, **kwargs)
    319 
    320     agg = aggregate

c:\dev\projects\weedget\venv\lib\site-packages\pandas\core\window\rolling.py in aggregate(self, func, *args, **kwargs)
    472         result, how = aggregate(self, func, *args, **kwargs)
    473         if result is None:
--> 474             return self.apply(func, raw=False, args=args, kwargs=kwargs)
    475         return result
    476 

c:\dev\projects\weedget\venv\lib\site-packages\pandas\core\window\rolling.py in __getattr__(self, attr)
    206             return self[attr]
    207 
--> 208         raise AttributeError(
    209             f"'{type(self).__name__}' object has no attribute '{attr}'"
    210         )

AttributeError: 'ExponentialMovingWindow' object has no attribute 'apply'

Comment From: mroeschke

Thanks for the report. I think conceptually it's not well defined what a custom exponentially weighted udf would return. In the meanwhile, I think it would be better if ExponentialMovingWindow.apply would raise a NotImplementedError

Comment From: gioxc88

Thanks for the report. I think conceptually it's not well defined what a custom exponentially weighted udf would return. In the meanwhile, I think it would be better if ExponentialMovingWindow.apply would raise a NotImplementedError

Thanks for looking into it. I don't want to oversimplify but in my opinion is relatively straightforward. If I use .apply(fn) on ewm I would expect fn to receive the weighted series according to the exponential weights.

Comment From: hudson-ai

@gioxc88 what is a weighted series though? It seems that fn would have to take both the series and the weights as arguments. Think about how you would have to implement the standard deviation, for example. You cannot simply multiply the values times the weights.

Comment From: gioxc88

@gioxc88 what is a weighted series though? It seems that fn would have to take both the series and the weights as arguments. Think about how you would have to implement the standard deviation, for example. You cannot simply multiply the values times the weights.

@hudson-ai thanks for the answer. You are indeed correct. The function passed to apply should receive both the series and the weights.

Comment From: KIC

@gioxc88 what is a weighted series though? It seems that fn would have to take both the series and the weights as arguments. Think about how you would have to implement the standard deviation, for example. You cannot simply multiply the values times the weights.

that's exactly what I would expect. alternatively the current row along with the last result and the alpha factor