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

xarray Datasets are not correctly serialized to netcdf #111

bocklund opened this issue Jul 27, 2017 · 1 comment

xarray Datasets are not correctly serialized to netcdf #111

bocklund opened this issue Jul 27, 2017 · 1 comment


Copy link

@bocklund bocklund commented Jul 27, 2017

import numpy as np
import xarray as xr
import datetime
data = xr.DataArray(np.random.randn(2, 3), coords={'x': ['a', 'b']}, dims=('x', 'y'))
ds = xr.Dataset({'z': data})
ds.to_netcdf('')  # works
ds.attrs['created'] =
ds.to_netcdf('')  # fails

I thought about opening this issue upstream, but their solution for handling datetimes as DataArrays is precisely to use the attrs as metadata for that array. I don't think they would support generic serialization of datetimes that are in attrs.

It seems like we should either not use datetimes or just serialize/deserialize ourselves.

Copy link

@richardotis richardotis commented Jul 28, 2017

I would be comfortable converting datetimes to strings on creation. We don't use them in any library code, from a readability standpoint it's the same for the user, and it's trivial for downstream code to convert the string to a datetime object if programmatic access is needed. Also, it would be a one line change.

@bocklund bocklund closed this in b63820b Jul 28, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.