Skip to content

cumsum drops coordinate in Dataset but not DataArray #9735

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
5 tasks done
delgadom opened this issue Nov 6, 2024 · 1 comment
Closed
5 tasks done

cumsum drops coordinate in Dataset but not DataArray #9735

delgadom opened this issue Nov 6, 2024 · 1 comment
Labels
bug needs triage Issue that has not been reviewed by xarray team member

Comments

@delgadom
Copy link
Contributor

delgadom commented Nov 6, 2024

What happened?

Inconsistent behavior between cumulative sum on Dataset and DataArrray - Dataset.cumsum drops coordinate along reduction dim (even though cumsum is not actually a reduction).

DataArray does not do this. The dimension is still there, but as a dimension without a coordinate.

What did you expect to happen?

Expected Dataset to behave like DataArray, without dropping the coordinate.

Minimal Complete Verifiable Example

import xarray as xr

ds = xr.Dataset({"var1": (('dim1', ), [0, 1, 2])}, coords={"dim1": ['a', 'b', 'c']})
print(ds)

print("\n\nDataset cumsum:\n")
print(ds.cumsum(dim="dim1"))

print("\n\nDataArray cumsum:\n")
print(ds["var1"].cumsum(dim="dim1"))

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.

Relevant log output

<xarray.Dataset> Size: 36B
Dimensions:  (dim1: 3)
Coordinates:
  * dim1     (dim1) <U1 12B 'a' 'b' 'c'
Data variables:
    var1     (dim1) int64 24B 0 1 2


Dataset cumsum:

<xarray.Dataset> Size: 24B
Dimensions:  (dim1: 3)
Dimensions without coordinates: dim1
Data variables:
    var1     (dim1) int64 24B 0 1 3


DataArray cumsum:

<xarray.DataArray 'var1' (dim1: 3)> Size: 24B
array([0, 1, 3])
Coordinates:
  * dim1     (dim1) <U1 12B 'a' 'b' 'c'

Anything else we need to know?

No response

Environment

INSTALLED VERSIONS

commit: None
python: 3.11.4 | packaged by conda-forge | (main, Jun 10 2023, 18:08:41) [Clang 15.0.7 ]
python-bits: 64
OS: Darwin
OS-release: 24.0.0
machine: arm64
processor: arm
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: ('en_US', 'UTF-8')
libhdf5: 1.14.0
libnetcdf: 4.9.2

xarray: 2024.10.0
pandas: 2.2.3
numpy: 1.24.3
scipy: 1.14.1
netCDF4: 1.6.4
pydap: None
h5netcdf: None
h5py: 3.8.0
zarr: 2.18.3
cftime: 1.6.2
nc_time_axis: None
iris: None
bottleneck: 1.3.7
dask: 2024.8.0
distributed: 2024.8.0
matplotlib: 3.7.1
cartopy: 0.24.0
seaborn: 0.12.2
numbagg: None
fsspec: 2023.6.0
cupy: None
pint: None
sparse: None
flox: 9.11
numpy_groupies: 0.11.2
setuptools: 67.7.2
pip: 23.1.2
conda: None
pytest: None
mypy: None
IPython: 8.14.0
sphinx: None

@delgadom delgadom added bug needs triage Issue that has not been reviewed by xarray team member labels Nov 6, 2024
@dcherian
Copy link
Contributor

dcherian commented Nov 6, 2024

Dupe of #6528

@dcherian dcherian closed this as not planned Won't fix, can't repro, duplicate, stale Nov 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug needs triage Issue that has not been reviewed by xarray team member
Projects
None yet
Development

No branches or pull requests

2 participants