Commit 19d66e31 authored by PIOLLE's avatar PIOLLE
Browse files

fixed append method

parent 422cf329
...@@ -208,7 +208,7 @@ class Feature(Dataset, ABC): ...@@ -208,7 +208,7 @@ class Feature(Dataset, ABC):
def append(self, def append(self,
feature, feature,
prefix: str = None, prefix: str = '',
add_coords: bool = False, add_coords: bool = False,
as_new_dims: bool = False, as_new_dims: bool = False,
fields: str = None): fields: str = None):
...@@ -254,28 +254,27 @@ class Feature(Dataset, ABC): ...@@ -254,28 +254,27 @@ class Feature(Dataset, ABC):
added_fields = feature.fieldnames added_fields = feature.fieldnames
if add_coords: if add_coords:
added_fields.extend(feature.coordnames) added_fields.extend(feature.coordnames)
added_fields = list(set(added_fields))
# append fields # append fields
for fieldname in added_fields: for fieldname in added_fields:
if fieldname in feature.fieldnames: if fieldname in feature.fieldnames:
field = feature.get_field(fieldname).clone() field = feature.get_field(fieldname).clone()
elif fieldname in feature.coords: elif fieldname in feature.coordnames:
field = feature.get_coord(fieldname).clone() field = feature.get_coord(fieldname).clone()
else: else:
raise ValueError("field {} not found in feature".format( raise ValueError("field {} not found in feature".format(
fieldname)) fieldname))
field.rename('{}{}'.format(prefix, field.name))
if prefix is not None:
field.rename('{}{}'.format(prefix, field.name))
if as_new_dims: if as_new_dims:
# we ensure dim and field names can not be the same (raise an # we ensure dim and field names can not be the same (raise an
# error with xarray # error with xarray
field._array = field._array.swap_dims( field._array = field._array.swap_dims(
{_: '{}_{}'.format(prefix, _) for _ in field.dims}) {_: '{}{}'.format(prefix, _) for _ in field.dims})
self.add_field(field) self.add_field(field)
def get_values(self, *args, **kwargs): def get_values(self, *args, **kwargs):
""" """
See: See:
......
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