-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
A way to generate automatically-numbered coords #2067
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
If I understand correctly, instead of writing I agree that it's sometimes convenient to automatically get coordinates 0 to |
My issue is not so much with the On the bright side, the mistakes are quickly caught when the code executes at runtime. On the other side, they can be entirely avoided. Of course, xarray doesn't have to do this; a user concerned about making these mistakes can easily capture this usage pattern in a wrapper function around def assign_auto_coords(da, *dims):
"""Give each specified dimension of a DataArray or Dataset automatic coords from 0 to n-1."""
return da.assign_coords(**{dim: range(self.sizes[dim]) for dim in dims}) it's merely that first-class support during construction would be nice to have. |
I think this will share a similar API with the evenly spaced coordinate discussed in issue #1650. I thought the possible API would be
where it will construct a evenly spaced coordinate. |
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 |
It is great that
xarray
supports dimensions without coords, but sometimes I think it would be useful to be able to easily opt into autogenerated coords from 0 ton-1
. This can be useful to obtain DataArrays for pointwise indexing:My issue with the above is that
layer=list(range(ds.sizes['layer']))
is verbose and fails to be DRY. My thought for such an API is that xarray could maybe have a special constant for auto-assignment, usable in any method that takes input coords:(Additionally, perhaps
xr.AUTO
could be a function/class, so thatxr.AUTO(start)
produces indices starting atstart
.)The text was updated successfully, but these errors were encountered: