Skip to content
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

to_dataset lossy #1047

Closed
tdimiduk opened this issue Oct 14, 2016 · 5 comments
Closed

to_dataset lossy #1047

tdimiduk opened this issue Oct 14, 2016 · 5 comments

Comments

@tdimiduk
Copy link

I am looking at saving a DataArray to netcdf. This appears to require turning into a dataset. However, the conversion to and from datasets appears to be lossy.

d = DataArray(...)
n = d.to_dataset().to_array()

looses attrs and the name of the DataArray gets moved to a "variable" coordinate.

I can manually add the attrs to the created dataset, but it seems like they should either be transfered by default, or have an option to preserve them. Is there a reason this is not done?

@fmaussion
Copy link
Member

If you don't use to_array() but simply acces the variable everything is fine:

import xarray as xr
da = xr.DataArray([1, 2, 3], name='da', attrs={'myattr':3})
da.to_dataset().da
<xarray.DataArray 'da' (dim_0: 3)>
array([1, 2, 3])
Coordinates:
  * dim_0    (dim_0) int64 0 1 2
Attributes:
    myattr: 3

@tdimiduk
Copy link
Author

Ah thanks. Would you be be interested in a pull request to make that more clear in the docs?

@shoyer
Copy link
Member

shoyer commented Oct 14, 2016

Sure, improvements to the docs are always welcome!

Note that in the next release of xarray we will have a DataArray.to_netcdf method (and open_dataarray).

@tdimiduk
Copy link
Author

Oh, that will be excellent. When is that coming out?

On Fri, Oct 14, 2016 at 4:12 PM, Stephan Hoyer [email protected]
wrote:

Sure, improvements to the docs are always welcome!

Note that in the next release of xarray we will have a DataArray.to_netcdf
method (and open_dataarray).


You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
#1047 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/AArz9M4l7AKamroG_E8swXNbZoxxxzJIks5qz-IigaJpZM4KXT2N
.

@shoyer
Copy link
Member

shoyer commented Oct 14, 2016

I'm trying to get a couple of big PRs (#1017 and #1028) into the next major release. So probably 2-4 weeks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants