np.minimum.accumulate(da) doesn't work
Open
Nobody has claimed this yet.
topic-arrays
- Dominant language
- Python
- Stars
- 4.2k
- Forks
- 1.4k
- Avg merge
- 2d 15h
- Merged PRs (30d)
- 14
Description
Code Sample, a copy-pastable example if possible
In [1]: import numpy as np
In [2]: import xarray as xr
In [3]: np.minimum.accumulate(np.array([3,2,4,1]))
Out[3]: array([3, 2, 2, 1], dtype=int32)
In [4]: np.minimum.accumulate(xr.DataArray([3,2,4,1]))
---------------------------------------------------------------------------
NotImplementedError Traceback (most recent call last)
<ipython-input-7-7205433fb365> in <module>()
----> 1 np.minimum.accumulate(xr.DataArray([3,2,4,1]))
~\Anaconda3\lib\site-packages\xarray\core\arithmetic.py in __array_ufunc__(self, ufunc, method, *inputs, **kwargs)
49 'alternative, consider explicitly converting xarray objects '
50 'to NumPy arrays (e.g., with `.values`).'
---> 51 .format(method, ufunc))
52
53 if any(isinstance(o, SupportsArithmetic) for o in out):
NotImplementedError: accumulate method for ufunc <ufunc 'minimum'> is not implemented on xarray objects, which currently only support the __call__ method. As an alternative, consider explicitly converting xarray objects to NumPy arrays (e.g., with `.values`).
Problem description
I would expect this to work, like xr.apply_ufunc(np.minimum.accumulate, xr.DataArray([3,2,4,1])):
Expected Output
Out[4]: <xarray.DataArray (dim_0: 4)>
array([3, 2, 2, 1])
Dimensions without coordinates: dim_0
Output of xr.show_versions()
```
commit: None
python: 3.6.4.final.0
python-bits: 64
OS: Windows
OS-release: 10
machine: AMD64
processor: Intel64 Family 6 Model 62 Stepping 4, GenuineIntel
byteorder: little
LC_ALL: None
LANG: None
LOCALE: None.None
xarray: 0.10.2
pandas: 0.22.0
numpy: 1.14.2
scipy: 1.0.0
netCDF4: None
h5netcdf: 0.5.0
h5py: 2.7.1
Nio: None
zarr: None
bottleneck: 1.2.1
cyordereddict: None
dask: 0.17.1
distributed: 1.21.3
matplotlib: 2.2.2
cartopy: None
seaborn: 0.8.1
setuptools: 39.0.1
pip: 9.0.2
conda: 4.3.34
pytest: 3.4.2
IPython: 6.2.1
sphinx: 1.7.1
```
Originally posted posted to https://groups.google.com/forum/#!topic/xarray/LiwxrJcJBwY.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with xarray/core/arithmetic.py, where the traceback shows array_ufunc rejecting the accumulate method. Reproduce the example with np.minimum.accumulate on a DataArray and verify that the operation returns a DataArray with the expected values and dimensions.
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
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100