question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`cumsum` providing correct behavior for non-coordinate DataArrays?

See original GitHub issue

In 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:open
  • Created 6 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
pwolframcommented, Mar 28, 2017

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-dimensional da. But, it may not be worth the effort to fix this issue relative to other issues.

0reactions
stale[bot]commented, Mar 1, 2019

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 stale label; otherwise it will be marked as closed automatically

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found