-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Inconsistency between the types of Dataset.dims and DataArray.dims #921
Comments
What are the arguments against having |
I guess that's a third option! In that case, we'd have to add The main downside is that we'd still be stuck without any idea way to get dimension sizes by name -- |
I frequently need to pull out the dimension names, and I've never needed to pull out their sizes. I realize that the internals need to do that though. And maybe my use case is specific. Zooming out a bit: the access pattern for most of these (variables, coords) is indeed an I could certainly understand a convenience But I"m coming from a place of less context without that much confidence... |
Indeed, this is why this discrepancy has survived for so long. Both
Agreed, it is a little weird, and probably unnecessary. It is arguably a left-over from the very early days of xarray (before we had a DataArray type!). It occurs to me that it's not hard to pull sizes out of |
Thanks for the, as ever, thoughtful response Should we move |
One thing I like about CC @jhamman in case he has thoughts here. |
It seems to me that I do see the utility in switching to an |
With optional indexes (#1017) meaning that Rather than resolving the type inconsistency of |
This allows for consistent access to dimension lengths on ``Dataset`` and ``DataArray`` xref pydata#921 (doesn't resolve it 100%, but should help significantly)
This allows for consistent access to dimension lengths on ``Dataset`` and ``DataArray`` xref pydata#921 (doesn't resolve it 100%, but should help significantly)
This allows for consistent access to dimension lengths on ``Dataset`` and ``DataArray`` xref #921 (doesn't resolve it 100%, but should help significantly)
In order to maintain a list of currently relevant issues, we mark issues as stale after a period of inactivity |
We have |
DataArray.dims
is currently a tuple, whereasDataset.dims
is a dict. This results in ugly code like this, taken fromxarray/core/group.py
:One way to resolve this inconsistency would be switch
DataArray.dims
to a (frozen)OrderedDict
. The downside is that code likex.dims[0]
wouldn't work anymore (unless we add some terrible fallback logic). You'd have to writex.dims.keys()[0]
, which is pretty ugly. On the plus side,x.dims['time']
would always return the size of the time dimension, regardless of whetherx
is a DataArray or Dataset.Another option would be to add an attribute
dim_shape
(or some other name) that serves as an alias todims
on Dataset and an alias toOrderedDict(zip(dims, shape))
on DataArray. This would be fully backwards compatible, but further pollute the namespace on Dataset and DataArray.The text was updated successfully, but these errors were encountered: