`cumsum` providing correct behavior for non-coordinate DataArrays?
See original GitHub issueIn the case of a DataArray without coordinates, should cumsum work without specifying an axis, e.g., da.cumsum() is valid? This is not currently the obtained behavior.
In [1]: import xarray as xr
imp
In [2]: import numpy as np
In [3]: da = xr.DataArray(np.arange(10))
In [4]: da
Out[4]:
<xarray.DataArray (dim_0: 10)>
array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
Dimensions without coordinates: dim_0
In [5]: da.cumsum(axis=0)
Out[5]:
<xarray.DataArray (dim_0: 10)>
array([ 0, 1, 3, 6, 10, 15, 21, 28, 36, 45])
Dimensions without coordinates: dim_0
In [6]: da.cumsum()
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-5-4ff0efc782ee> in <module>()
----> 1 da.cumsum()
/Users/pwolfram/src/xarray/xarray/core/common.pyc in wrapped_func(self, dim, axis, skipna, keep_attrs, **kwargs)
17 keep_attrs=False, **kwargs):
18 return self.reduce(func, dim, axis, keep_attrs=keep_attrs,
---> 19 skipna=skipna, allow_lazy=True, **kwargs)
20 else:
21 def wrapped_func(self, dim=None, axis=None, keep_attrs=False,
/Users/pwolfram/src/xarray/xarray/core/dataarray.pyc in reduce(self, func, dim, axis, keep_attrs, **kwargs)
1146 summarized data and the indicated dimension(s) removed.
1147 """
-> 1148 var = self.variable.reduce(func, dim, axis, keep_attrs, **kwargs)
1149 return self._replace_maybe_drop_dims(var)
1150
/Users/pwolfram/src/xarray/xarray/core/variable.pyc in reduce(self, func, dim, axis, keep_attrs, allow_lazy, **kwargs)
898 if dim is None and axis is None:
899 raise ValueError("must supply either single 'dim' or 'axis' "
--> 900 "argument to %s" % (func.__name__))
901
902 if dim is not None:
ValueError: must supply either single 'dim' or 'axis' argument to cumsum
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
xarray.combine_by_coords
Attempt to auto-magically combine the given datasets (or data arrays) into one by using dimension coordinates. This function attempts to combine a group...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Thanks @fmaussion, it just seems strange that if the data is one-dimensional we return an error. I would agree that we probably want an error for dimensionality larger than one. I think the thing to change here is to make
da.cumsum()work for one-dimensionalda. But, it may not be worth the effort to fix this issue relative to other issues.In order to maintain a list of currently relevant issues, we mark issues as stale after a period of inactivity
If this issue remains relevant, please comment here or remove the
stalelabel; otherwise it will be marked as closed automatically