nonzero method for xr.DataArray
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 4.2k
- Forks
- 1.4k
- Avg merge
- 2d 15h
- Merged PRs (30d)
- 14
Description
np.nonzero to DataArray returns a wrong result,
In [4]: da = xr.DataArray(np.arange(12).reshape(4, 3), dims=['x', 'y'],
...: coords={'x': [0, 1, 2, 3], 'y': ['a', 'b', 'c']})
...: np.nonzero(da)
...:
Out[4]:
<xarray.DataArray (x: 2, y: 11)>
array([[0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3],
[1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2]])
Coordinates:
* x (x) int64 0 1 2 3
* y (y) <U1 'a' 'b' 'c'
Problem description
Apparently, the dimensions and the coordinates conflict each other.
I think we can have our own nonzero method, which may return a Dataset consisting of indexes and appropriate coordinates.
Output of xr.show_versions()
xarray: 0.9.6-172-gc58d142
pandas: 0.21.0
numpy: 1.13.1
scipy: 0.19.1
netCDF4: None
h5netcdf: None
Nio: None
bottleneck: 1.2.1
cyordereddict: None
dask: 0.16.0
matplotlib: 2.0.2
cartopy: None
seaborn: 0.7.1
setuptools: 36.5.0
pip: 9.0.1
conda: 4.3.30
pytest: 3.2.3
IPython: 6.0.0
sphinx: 1.6.3
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
Reproduce the reported result with the DataArray example and inspect how NumPy's nonzero dispatch interacts with xarray dimensions and coordinates. The issue names no implementation file or test; done would require an agreed nonzero behavior that preserves appropriate indexes and coordinates, plus regression coverage.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- numpy, python
- Domain
- data
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100