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
Environment
Details
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
What happened?
The combination of cumulative + argmax does not lead to the (at least from me) expected result.
Example:
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
Environment
Details
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