pydata / pydata/xarray

cumulate+argmax uses padded index instead of absolute index

Open
#11,336 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug needs triage
Dominant language
Python
Stars
4.2k
Forks
1.4k
Avg merge
2d 15h
Merged PRs (30d)
14

Description

What happened?

The combination of cumulative + argmax does not lead to the (at least from me) expected result.
Example:

import numpy as np
import xarray as xr
da = xr.DataArray([1,2,1.5,3.5,4], coords={'time': ('time', np.arange(5))})
da.cumulative('time').argmax()
# [4., 4., 3., 4., 4.]
# expected [0, 1, 1,3,4]

If I want to fetch the time for the largest value until that value I would use something like above cumulative('time').argmax(). However it doesnt not return the index but seems to use some kind of padded rolling array and fetches the argmax from this. Maybe this is the expected behaviour but I was definitely suprised.

MVCE confirmation
  • Minimal example — the example is as focused as reasonably possible to demonstrate the underlying issue in xarray.
  • Complete example — the example is self-contained, including all data and the text of any traceback.
  • Verifiable example — the example copy & pastes into an IPython prompt or Binder notebook, returning the result.
  • New issue — a search of GitHub Issues suggests this is not a duplicate.
  • Recent environment — the issue occurs with the latest version of xarray and its dependencies.
Environment

INSTALLED VERSIONS

commit: None
python: 3.13.8 | packaged by conda-forge | (main, Oct 13 2025, 14:15:33) [GCC 14.3.0]
python-bits: 64
OS: Linux
OS-release: 5.14.0-427.22.1.el9_4.x86_64
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: C.UTF-8
LOCALE: ('C', 'UTF-8')
libhdf5: 1.14.6
libnetcdf: 4.9.3

xarray: 2025.10.1
pandas: 2.3.3
numpy: 2.3.3
scipy: 1.16.2
netCDF4: 1.7.3
pydap: None
h5netcdf: None
h5py: None
zarr: 2.18.7
cftime: 1.6.4
nc_time_axis: None
iris: None
bottleneck: 1.6.0
dask: 2025.10.0
distributed: 2025.10.0
matplotlib: 3.10.6
cartopy: 0.24.0
seaborn: 0.13.2
numbagg: None
fsspec: 2025.9.0
cupy: None
pint: 0.25
sparse: 0.17.0
flox: 0.10.7
numpy_groupies: 0.11.3
setuptools: 80.9.0
pip: 25.3
conda: None
pytest: 8.4.2
mypy: None
IPython: 9.6.0
sphinx: 7.4.7

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the minimal Python example and tracing the cumulative and argmax entry points that produce the padded indices. Verify the behavior against the expected absolute indices and add regression coverage showing the cumulative argmax result for this example.

Written by the indexing model from the issue text.

Assessment

Tech stack
numpy, python
Domain
data
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.