xarray icon indicating copy to clipboard operation
xarray copied to clipboard

how to specify `ignore_na` and `adjust` in `DataArray.rolling_exp`?

Open abcde-1447 opened this issue 3 years ago • 3 comments

What is your issue?

Hi, I am trying to compute the moving average like the following in pandas using DataArray.rolling_exp:

df.ewm(alpha=0.9, ignore_na=True, adjust=True).mean()

does anyone know how to specify ignore_na and adjust in DataArray.rolling_exp?

Thanks!

abcde-1447 avatar Mar 21 '22 21:03 abcde-1447

Unfortunately those aren't in the interface at the moment. The default adjust is True.

I hadn't found any cases for ignore_na=True, though maybe this is one? If the missing values are common across the dimensions that this is broadest over, dropping missing values and reindexing by the existing indexes has the same semantics.

Could you explain your use case?

max-sixty avatar Mar 21 '22 21:03 max-sixty

Thanks for the comment! @max-sixty

A typical use case for ignore_na=True is when we have a dataframe which has different nan locations for different columns, e.g. df = pd.DataFrame({'a': pd.Series([0,np.nan, np.nan, 1,2]), 'b': pd.Series([np.nan, np.nan, 0, 1,2])}). In this case we could technically split the dataframe into several pd.Series and then apply ewm separately, but it would be more convenient if we can do this directly on the dataframe.

abcde-1447 avatar Mar 22 '22 20:03 abcde-1447

Yes that definitely makes sense. I was wondering what the underlying use case was, such that you want to ignore the missing values in your calc?

I think this is a reasonable feature request, but would have to come from a contribution. It wouldn't be the most complex contribution — it would involve adding the code from the pandas routine into the numbagg code, and then updating the kwargs in xarray.

I'd be happy to do the release of numbagg once the code is in, since we don't do regular releases like we do in xarray.

max-sixty avatar Mar 22 '22 23:03 max-sixty