-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Closed
Description
This is due to setting multi-dimensional attributes being an error, as of the latest netCDF4-Python release: https://github.com/Unidata/netcdf4-python/blob/master/Changelog
E.g., as seen on Appveyor: https://ci.appveyor.com/project/shoyer/xray/builds/22834250/job/9q0ip6i3cchlbkw2
================================== FAILURES ===================================
___________________ TestValidateAttrs.test_validating_attrs ___________________
self = <xarray.tests.test_backends.TestValidateAttrs object at 0x00000096BE5FAFD0>
def test_validating_attrs(self):
def new_dataset():
return Dataset({'data': ('y', np.arange(10.0))},
{'y': np.arange(10)})
def new_dataset_and_dataset_attrs():
ds = new_dataset()
return ds, ds.attrs
def new_dataset_and_data_attrs():
ds = new_dataset()
return ds, ds.data.attrs
def new_dataset_and_coord_attrs():
ds = new_dataset()
return ds, ds.coords['y'].attrs
for new_dataset_and_attrs in [new_dataset_and_dataset_attrs,
new_dataset_and_data_attrs,
new_dataset_and_coord_attrs]:
ds, attrs = new_dataset_and_attrs()
attrs[123] = 'test'
with raises_regex(TypeError, 'Invalid name for attr'):
ds.to_netcdf('test.nc')
ds, attrs = new_dataset_and_attrs()
attrs[MiscObject()] = 'test'
with raises_regex(TypeError, 'Invalid name for attr'):
ds.to_netcdf('test.nc')
ds, attrs = new_dataset_and_attrs()
attrs[''] = 'test'
with raises_regex(ValueError, 'Invalid name for attr'):
ds.to_netcdf('test.nc')
# This one should work
ds, attrs = new_dataset_and_attrs()
attrs['test'] = 'test'
with create_tmp_file() as tmp_file:
ds.to_netcdf(tmp_file)
ds, attrs = new_dataset_and_attrs()
attrs['test'] = {'a': 5}
with raises_regex(TypeError, 'Invalid value for attr'):
ds.to_netcdf('test.nc')
ds, attrs = new_dataset_and_attrs()
attrs['test'] = MiscObject()
with raises_regex(TypeError, 'Invalid value for attr'):
ds.to_netcdf('test.nc')
ds, attrs = new_dataset_and_attrs()
attrs['test'] = 5
with create_tmp_file() as tmp_file:
ds.to_netcdf(tmp_file)
ds, attrs = new_dataset_and_attrs()
attrs['test'] = 3.14
with create_tmp_file() as tmp_file:
ds.to_netcdf(tmp_file)
ds, attrs = new_dataset_and_attrs()
attrs['test'] = [1, 2, 3, 4]
with create_tmp_file() as tmp_file:
ds.to_netcdf(tmp_file)
ds, attrs = new_dataset_and_attrs()
attrs['test'] = (1.9, 2.5)
with create_tmp_file() as tmp_file:
ds.to_netcdf(tmp_file)
ds, attrs = new_dataset_and_attrs()
attrs['test'] = np.arange(5)
with create_tmp_file() as tmp_file:
ds.to_netcdf(tmp_file)
ds, attrs = new_dataset_and_attrs()
attrs['test'] = np.arange(12).reshape(3, 4)
with create_tmp_file() as tmp_file:
> ds.to_netcdf(tmp_file)
xarray\tests\test_backends.py:3450:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
xarray\core\dataset.py:1323: in to_netcdf
compute=compute)
xarray\backends\api.py:767: in to_netcdf
unlimited_dims=unlimited_dims)
xarray\backends\api.py:810: in dump_to_store
unlimited_dims=unlimited_dims)
xarray\backends\common.py:262: in store
self.set_attributes(attributes)
xarray\backends\common.py:278: in set_attributes
self.set_attribute(k, v)
xarray\backends\netCDF4_.py:418: in set_attribute
_set_nc_attribute(self.ds, key, value)
xarray\backends\netCDF4_.py:294: in _set_nc_attribute
obj.setncattr(key, value)
netCDF4\_netCDF4.pyx:2781: in netCDF4._netCDF4.Dataset.setncattr
???
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> ???
E ValueError: multi-dimensional array attributes not supported
netCDF4\_netCDF4.pyx:1514: ValueError
Metadata
Metadata
Assignees
Labels
No labels