def _add_field(self, name, val=None, unit=None, write_level=None, suffix=None, **field_args): """Add a {field_type} field to the dataset""" if name in self._fields: raise exceptions.FieldExistsError( f"Field {name!r} already exists in dataset") # Create collections for nested fields collection, _, field_name = name.rpartition(".") if collection and collection not in self._fields: self.add_collection(collection) # Create field field = func(num_obs=self.num_obs, name=field_name, val=val, unit=unit, write_level=write_level, **field_args) # Add field to list of fields fields = getattr(self, collection) if collection else self._fields fields[field_name] = field
def update_from(self, other: "Dataset") -> None: """Transfers dataset fields from other Dataset to this Dataset This will not create a copy of the data in the other Dataset """ self.num_obs = other.num_obs for fieldname, field in other._fields.items(): if fieldname in self._fields: raise exceptions.FieldExistsError( f"Field {fieldname!r} already exists in dataset") self._fields.update({fieldname: field}) self.meta.update(other.meta)