def concat_features(data_sets: Iterable[DataSet],
dimension: str = "generated") -> DataSet:
"""
Concatenates the specified data sets along the specified feature dimension.
The feature matrices of each instance are concatenated along the specified dimension. All data sets must have the
specified feature dimension. Additionally, all metadata, including names and sizes of other feature dimensions must
be identical for all data sets.
Parameters
----------
data_sets: list of DataSet
Data sets which should be concatenated
dimension: str, default "generated"
Feature dimension along which features should be concatenated.
Returns
-------
DataSet
A new data set created by concatenating the specified data sets along the specified feature dimension
Raises
------
ValueError
If the specified feature dimension is not present in some data sets
"""
for data_set in data_sets:
# noinspection PyProtectedMember
if dimension not in data_set._data.dims:
raise ValueError("dimension '{}' missing in some data sets".format(dimension))
# noinspection PyProtectedMember
mutable = all([data_set._mutable for data_set in data_sets])
# noinspection PyProtectedMember
new_data = xr.concat([data_set._data for data_set in data_sets],
dim=dimension,
data_vars="minimal",
compat="identical")
# noinspection PyTypeChecker
return DataSet(data=new_data,
mutable=mutable)
评论列表
文章目录