home / github / issues

Menu
  • GraphQL API
  • Search all tables

issues: 578736255

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
578736255 MDU6SXNzdWU1Nzg3MzYyNTU= 3855 `rolling.mean` gives negative values on non-negative array. 2272878 closed 0     6 2020-03-10T17:13:46Z 2023-11-14T08:25:58Z 2020-03-10T18:51:13Z CONTRIBUTOR      

When doing a rolling mean on an array with no negative values, the result somehow contains negative values anyway. This shouldn't be possible, since the mean of non-negative values can never be zero. Further, it only happens when using the mean method directly, not when using reduce(np.mean) nor construct().mean().

MCVE Code Sample

Take the following xarray Dataarray

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

soundlen=10000 np.random.seed(1) noise = np.random.randn(soundlen) noise = sp.signal.hann(soundlen) noise2 = noise*2

xnoise = xr.DataArray(noise2, dims='temp', coords={'temp': np.arange(soundlen)}) print(xnoise.min()) ```

The result is 0. That is, it has no values less than 0.

Using reduce(np.mean) has no negative values, either, since the mean of non-negative values can never be negative:

```Python

print(xroll.reduce(np.mean).min())
<xarray.DataArray ()> array(2.90664355e-15) ```

Similarly, using mean through construct has no negative values:

Python print(xroll.construct('new').mean('new').min()) <xarray.DataArray ()> array(0.)

However, using the mean method directly does give negative values:

Python print(xroll.mean().min()) <xarray.DataArray ()> array(1.72090357e-15)

This mathematically shouldn't be possible.

Versions

xarray: 0.15.0 pandas: 0.25.3 numpy: 1.17.4 scipy: 1.4.1 netCDF4: 1.5.3 pydap: None h5netcdf: None h5py: 2.10.0 Nio: None zarr: None cftime: 1.0.4.2 nc_time_axis: None PseudoNetCDF: None rasterio: None cfgrib: None iris: None bottleneck: 1.3.1 dask: 2.11.0 distributed: 2.11.0 matplotlib: 3.1.3 cartopy: None seaborn: 0.10.0 numbagg: None setuptools: 44.0.0 pip: 20.0.2 conda: None pytest: 5.3.5 IPython: 7.12.0 sphinx: 2.4.3

{
    "url": "https://api.github.com/repos/pydata/xarray/issues/3855/reactions",
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  completed 13221727 issue

Links from other tables

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