home / github / issue_comments

Menu
  • GraphQL API
  • Search all tables

issue_comments: 358982464

This data as json

html_url issue_url id node_id user created_at updated_at author_association body reactions performed_via_github_app issue
https://github.com/pydata/xarray/pull/1837#issuecomment-358982464 https://api.github.com/repos/pydata/xarray/issues/1837 358982464 MDEyOklzc3VlQ29tbWVudDM1ODk4MjQ2NA== 6815844 2018-01-19T14:35:31Z 2018-01-19T14:35:31Z MEMBER

During the work, I notice a somehow unexpected behavior of rolling.

I expected that with min_periods=1 option, we will get an array without nan, It is true with center=False and also pd.rolling.

```python In [2]: da = xr.DataArray(np.arange(10), dims='x') In [3]: da.rolling(x=3, min_periods=1, center=False).sum() Out[3]: <xarray.DataArray (x: 10)> array([ 0., 1., 3., 6., 9., 12., 15., 18., 21., 24.]) Dimensions without coordinates: x

In [5]: s = pd.Series(np.arange(10)) s.rolling(3, min_periods=1, center=True).sum() Out[7]: 0 1.0 1 3.0 2 6.0 3 9.0 4 12.0 5 15.0 6 18.0 7 21.0 8 24.0 9 17.0 dtype: float64 But with `center=True`, we have a `nan` at the end. In [4]: da.rolling(x=3, min_periods=1, center=True).sum() Out[4]: <xarray.DataArray (x: 10)> array([ 1., 3., 6., 9., 12., 15., 18., 21., 24., nan]) Dimensions without coordinates: x ```

It is because we make shift operation after the rolling. https://github.com/pydata/xarray/blob/74d8318c68be884134d449afad18dfe731d48b72/xarray/core/rolling.py#L263-L269

If we pad the array before the rolling operation instead of shift, we will not get the last nan and the result would be the same to pandas. (rolling.to_dataarray('window_dim') does this).

I think this path is more intuitive. Any thoughts?

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  289556132
Powered by Datasette · Queries took 160.892ms · About: xarray-datasette