home / github / issues

Menu
  • Search all tables
  • GraphQL API

issues: 2035084881

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
2035084881 I_kwDOAMm_X855TO5R 8541 rolling argmin() or argmax() gives the wrong result (are they inverted?) 87534521 closed 0     10 2023-12-11T08:21:51Z 2023-12-21T02:08:01Z 2023-12-21T02:08:01Z NONE      

What happened?

I was trying to compute a rolling argmax and argmin on a DataArray, something like: data.rolling(time=3).argmax()

What did you expect to happen?

The results of the operations look flipped, the result of rolling argmax looks like what a rolling argmin should give, and viceversa.

Minimal Complete Verifiable Example

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

Create a sample DataArray

data = xr.DataArray(np.arange(10), dims='time', coords={'time': np.arange(10)})

Apply rolling argmax

data.rolling(time=3, center=False).argmax()

The result should be 2 for every index starting from the third time step. However, the result is always 0 (like argmin?)

If we try applying argmin

data.rolling(time=3, center=False).argmin()

Then, the result is always 2, which should be the result for argmax. Are these methods switched?

By doing it using the reduce() method and passing np.argmax, it works as expected

data.rolling(time=3, center=False).reduce(np.argmax) ```

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.
  • [X] Recent environment — the issue occurs with the latest version of xarray and its dependencies.

Relevant log output

No response

Anything else we need to know?

No response

Environment

INSTALLED VERSIONS ------------------ commit: None python: 3.12.0 | packaged by conda-forge | (main, Oct 3 2023, 08:43:22) [GCC 12.3.0] python-bits: 64 OS: Linux OS-release: 5.14.21-150400.24.81-default machine: x86_64 processor: x86_64 byteorder: little LC_ALL: None LANG: de_DE.UTF-8 LOCALE: ('de_DE', 'UTF-8') libhdf5: 1.14.2 libnetcdf: 4.9.2 xarray: 2023.11.0 pandas: 2.1.3 numpy: 1.26.2 scipy: 1.11.4 netCDF4: 1.6.5 pydap: None h5netcdf: 1.3.0 h5py: 3.10.0 Nio: None zarr: None cftime: 1.6.3 nc_time_axis: None iris: None bottleneck: 1.3.7 dask: 2023.12.0 distributed: 2023.12.0 matplotlib: 3.8.2 cartopy: 0.22.0 seaborn: None numbagg: None fsspec: 2023.12.1 cupy: None pint: 0.22 sparse: None flox: None numpy_groupies: None setuptools: 68.2.2 pip: 23.3.1 conda: None pytest: None mypy: None IPython: 8.18.1 sphinx: 7.2.6
{
    "url": "https://api.github.com/repos/pydata/xarray/issues/8541/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

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