xarray.concat() with compat='identical' fails for DataArray attrs
Open
Nobody has claimed this yet.
topic-combine
- Dominant language
- Python
- Stars
- 4.2k
- Forks
- 1.4k
- Avg merge
- 2d 15h
- Merged PRs (30d)
- 14
Description
Not sure if it was ever supposed to work with numpy arrays, but it actually does 🤔:
>>> attr = np.array([[3, 4]])
>>> d1 = xr.Dataset({'z': 1}, attrs={'y': attr})
>>> d2 = xr.Dataset({'z': 2}, attrs={'y': attr.copy()})
>>> xr.concat([d1, d2], dim='z', compat='identical')
However, it fails if you use DataArray attrs:
>>> attr = xr.DataArray([3, 4], {'x': [1, 2]}, 'x')
>>> d1 = xr.Dataset({'z': 1}, attrs={'y': attr})
>>> d2 = xr.Dataset({'z': 2}, attrs={'y': attr.copy()})
>>> xr.concat([d1, d2], dim='z', compat='identical')
ValueError: The truth value of an array with more than one element is ambiguous.
Use a.any() or a.all()
Given that the check is simply (a is b) or (a == b), should it try to do something smarter for array-like attrs?
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
No files or tests are named. Start by reproducing the two concat examples in the issue and trace the compat='identical' attribute comparison. Done means equivalent DataArray attributes no longer trigger an ambiguous truth-value error while the existing NumPy-array behavior remains intact.
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
- Mostly clear
- Newbie friendliness
- 35/100