-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
DataArray.set_index throws error on documented input #3176
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Thanks for the issue @gwgundersen I think the docs are potentially a bit unclear, and maybe the error message. The existing intention of In [16]: arr = xr.DataArray(data=np.ones((2, 3)), dims=['x', 'y'], coords={'x': range(2), 'y': range(3), 'a': ('x', [3,4])})
In [17]: arr
Out[17]:
<xarray.DataArray (x: 2, y: 3)>
array([[1., 1., 1.],
[1., 1., 1.]])
Coordinates:
* x (x) int64 0 1
* y (y) int64 0 1 2
a (x) int64 3 4
In [18]: arr.set_index(x='a')
Out[18]:
<xarray.DataArray (x: 2, y: 3)>
array([[1., 1., 1.],
[1., 1., 1.]])
Coordinates:
* x (x) int64 3 4
* y (y) int64 0 1 2 We'd definitely be keen on a PR improving the error message (i.e. something like |
Thanks for the explanation. I'll create a PR and link to this issue this evening. |
Looking at this now, and I'm a little surprised at the verbiage. In your example, do you consider But I do think I see the use case. The point is that you can take an existing dimension's coordinates and set them as the coordinates for an alternative dimension? |
You're not alone; the proliferation and overlap of terms can be confusing at the least. Maybe we should have a glossary somewhere. Briefly:
💯 |
Thanks for these answers! On a related point, I'd be keen to open a PR for improved documentation for whatever object What do you think of the terminology "alternative" or "auxiliary" dimension? |
Looks like the idea of a glossary is already being discussed in #2410. |
Good work on finding that issue. I think even if we can get something brief in, that would be helpful. On the specific definitions:
For me 'dimension' has a precise definition from traditional sciences, so having our 'coordinate' be an additional / auxiliary / alternative dimension wouldn't be consistent with that (e.g. a 4-dimensional array would still be 4 dimensional regardless of how many coordinates it had).
👍 |
Problem Description
Docs for
DataArray.set_index
describe the mainindexes
argument as:This suggests that one can set a
DataArray
instance's coordinates by passing in a dimension and a list-like object of coordinates.MCVE
At first, I thought it might be because
coords
and_coords
were not being set in this case:but even if I set the coordinates first and then try to re-index, it fails:
Expected Output
I expect my MCVE to work based on the documentation.
Problem Solution
My guess is that the issue is Xarray is using the
merge_indexes
function (see here) from theDataset
module, and there is no concept of avariable
in aDataArray
.The text was updated successfully, but these errors were encountered: