home / github / issues

Menu
  • GraphQL API
  • Search all tables

issues: 1301023040

This data as json

id node_id number title user state locked assignee milestone comments created_at updated_at closed_at author_association active_lock_reason draft pull_request body reactions performed_via_github_app state_reason repo type
1301023040 I_kwDOAMm_X85NjAlA 6772 DataArrayRolling.mean() ignores `skipna=True` kwarg 16807224 open 0     2 2022-07-11T17:43:10Z 2023-02-21T16:53:35Z   NONE      

What happened?

In the following example, it appears that the skipna=True argument is being ignored, unless you call construct before taking the mean.

What did you expect to happen?

I expected: da.rolling(time=3).mean("time", skipna=True) == da.rolling(time=3).construct("window").mean("window", skipna=True)

Minimal Complete Verifiable Example

```Python import xarray as xr import numpy as np

da = xr.DataArray([0, 1, 2, np.NAN, 4, 5, 6], dims="time")

Results 1 and 2 produce the same array, without skipping NANs

result1 = da.rolling(time=3).mean("time", skipna=True) result2 = da.rolling(time=3).mean("time", skipna=False)

Results 3 and 4 produce the expected (different) arrays

result3 = da.rolling(time=3).construct("window").mean("window", skipna=True) result4 = da.rolling(time=3).construct("window").mean("window", skipna=False)

print(result1) print(result2) print(result3) print(result4) ```

MVCE confirmation

  • [X] Minimal example — the example is as focused as reasonably possible to demonstrate the underlying issue in xarray.
  • [X] Complete example — the example is self-contained, including all data and the text of any traceback.
  • [X] Verifiable example — the example copy & pastes into an IPython prompt or Binder notebook, returning the result.
  • [X] New issue — a search of GitHub Issues suggests this is not a duplicate.

Relevant log output

Python <xarray.DataArray (time: 7)> array([nan, nan, 1., nan, nan, nan, 5.]) Dimensions without coordinates: time <xarray.DataArray (time: 7)> array([nan, nan, 1., nan, nan, nan, 5.]) Dimensions without coordinates: time <xarray.DataArray (time: 7)> array([0. , 0.5, 1. , 1.5, 3. , 4.5, 5. ]) Dimensions without coordinates: time <xarray.DataArray (time: 7)> array([nan, nan, 1., nan, nan, nan, 5.]) Dimensions without coordinates: time

Anything else we need to know?

Note: the first two NaNs are expected due to the min_periods argument to rolling(), but the middle NaNs are what are unexpected when skipna = True

Environment

INSTALLED VERSIONS ------------------ commit: None python: 3.9.13 | packaged by conda-forge | (main, May 27 2022, 16:50:36) [MSC v.1929 64 bit (AMD64)] python-bits: 64 OS: Windows OS-release: 10 machine: AMD64 processor: AMD64 Family 23 Model 17 Stepping 0, AuthenticAMD byteorder: little LC_ALL: None LANG: None LOCALE: ('English_United States', '1252') libhdf5: 1.12.1 libnetcdf: 4.8.1 xarray: 0.19.0 pandas: 1.3.4 numpy: 1.21.2 scipy: 1.7.1 netCDF4: 1.6.0 pydap: None h5netcdf: None h5py: None Nio: None zarr: 2.12.0 cftime: 1.6.0 nc_time_axis: None PseudoNetCDF: None rasterio: 1.2.10 cfgrib: None iris: None bottleneck: None dask: 2022.6.1 distributed: 2022.6.1 matplotlib: 3.4.3 cartopy: 0.20.1 seaborn: None numbagg: None pint: 0.19.2 setuptools: 59.8.0 pip: 22.1.2 conda: None pytest: 7.1.2 IPython: 8.4.0 sphinx: None
{
    "url": "https://api.github.com/repos/pydata/xarray/issues/6772/reactions",
    "total_count": 1,
    "+1": 1,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  reopened 13221727 issue

Links from other tables

  • 2 rows from issues_id in issues_labels
  • 2 rows from issue in issue_comments
Powered by Datasette · Queries took 0.546ms · About: xarray-datasette