-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Attributes of Dataset coordinates are dropped/replaced when adding a DataArray #2245
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
This is because Line 579 in b8a342a
So the old co-ordinate (with attrs) is replaced by the new co-ordinate (without attrs). Example: |
Edit: I was thinking about it a little wrong although I can still see a use case. |
Encountered this issue this week, is there anything in the works to address this? |
Problem description
Attributes of Dataset coordinates are dropped or replaced when adding a DataArray with dimensions or coordinates that already exist in the Dataset. In addition the order of the Dataset's coordinates can change by adding a DataArray.
Expected Behaviour
Attributes of Dataset coordinates should not be altered by adding a DataArray to the Dataset, and the order of existing coordinates should be preserved.
More details and code examples
The following code shows the behaviour by adding new data variables to a Dataset using a
tuple
, aDataArray
(dimension without coordinates), and aVariable
.Output
The output shows that the attributes and the order of the Dataset's coordinates are preserved (as expected) when adding data variables using a
tuple
or aVariable
, but when using aDataArray
instead the attributes are dropped for the related coordinates, and the ordering of the Dataset's coordinates is changed.When adding DataArrays with coordinates to the Dataset, the attributes of the affected Dataset coordinates are replaced with the attributes of the DataArray's coordinates:
Output
This even happens for the DataArray
e
in the example above which has a common dimension'z'
with the Datasetds
, but different coordinate values. In this case the data and coordinate values are handled as one would expect: Theds.e
array is filled with NaNs (because the coordinate values do not match), and theds.z
coordinate values are not replaced by the DataArray'se.z
coordinate values. But the attributes of the Dataset's coordinates (ds.z.attrs
) are still replaced by the attributes of the DataArray's coordinates (e.z.attrs
).Output of
xr.show_versions()
The text was updated successfully, but these errors were encountered: