moving_average not working with latest pandas
middleflight opened this issue · comments
Hi, I think ewm/rolling/resample have moved to being methods on series from having been functions.
This stops the _window_calc function from working.
Potential work around is to call the function using "getattr" (line 371) , and specifying the function name (e.g."resample", rather than actual function ("pd.DataFrame.resample" line 134)
old
return self._window_calc(
column, periods, name='MA',
func=pd.DataFrame.resample, named_arg='rule', **kwargs
)
new
return self._window_calc(
column, periods, name='MA',
func="resample", named_arg='rule',
**kwargs
)
self.data[column].pipe(func, **{named_arg: period}).mean().plot(ax=ax,linestyle='--',label=f'{period if isinstance(period, str) else str(period) + "D"} {name}') ##old
getattr(self.data[column], func)(**{named_arg: period}).mean().plot(ax=ax,linestyle='--',label=f'{period if isinstance(period, str) else str(period) + "D"} {name}') ##new
Also, thanks for writing the book!
Hi there. Thanks for pointing this out. It's actually a much easier fix. As a heads-up, I was only able to reproduce this once I upgraded my pandas version beyond the one used for the book (which is 1.2.0 – see the requirements.txt file). To avoid any other issues with incompatibilities that arise naturally over time as you go through the book, I would recommend that you reinstall your virtual environment with all the versions matching.
Nice fix! Noted on the version. Thanks again!