Skip to content

xarray Datasets are not correctly serialized to netcdf #111

@bocklund

Description

@bocklund
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('netcdf_test.nc')  # works
ds.attrs['created'] = datetime.datetime.now()
ds.to_netcdf('netcdf_test_time.nc')  # 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions