Commit 71b9f482 authored by PIOLLE's avatar PIOLLE
Browse files

fixes to avoid xarray errors when saving

parent 979e0a29
...@@ -2014,6 +2014,10 @@ class Dataset(ABC): ...@@ -2014,6 +2014,10 @@ class Dataset(ABC):
saved_dataset[v].encoding.update(encoding) saved_dataset[v].encoding.update(encoding)
else:
# no fill value permitted by xarray for object type
saved_dataset[v].encoding.pop('_FillValue')
# adjust missing value attribute types if packing is applied # adjust missing value attribute types if packing is applied
for matt in ['valid_min', 'valid_max', 'valid_range']: for matt in ['valid_min', 'valid_max', 'valid_range']:
if 'dtype' not in saved_dataset[v].encoding: if 'dtype' not in saved_dataset[v].encoding:
......
...@@ -279,7 +279,7 @@ class Field(object): ...@@ -279,7 +279,7 @@ class Field(object):
for att, val in attrs: for att, val in attrs:
if att in FIELD_ATTRS: if att in FIELD_ATTRS:
result += ' # {} : {}\n'.format(att, val) result += ' # {} : {}\n'.format(att, val)
result += ' # fill_value : {}\n'.format(self.fill_value) result += ' # fill_value : {}\n'.format(str(self.fill_value))
# free form attributes # free form attributes
result = result + ' other attributes :\n' result = result + ' other attributes :\n'
......
...@@ -268,8 +268,10 @@ class Feature(Dataset, ABC): ...@@ -268,8 +268,10 @@ class Feature(Dataset, ABC):
if prefix is not None: if prefix is not None:
field.rename('{}{}'.format(prefix, field.name)) field.rename('{}{}'.format(prefix, field.name))
if as_new_dims: if as_new_dims:
field._array = field._array.rename( # we ensure dim and field names can not be the same (raise an
{_: '{}{}'.format(prefix, _) for _ in field.dims}) # error with xarray
field._array = field._array.swap_dims(
{_: '{}_{}'.format(prefix, _) for _ in field.dims})
self.add_field(field) self.add_field(field)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment