(
arrays: Iterable[T_DataArray],
dim: Hashable | T_Variable | T_DataArray | pd.Index,
data_vars: T_DataVars | Iterable[Hashable] | CombineKwargDefault,
coords: ConcatOptions | Iterable[Hashable] | CombineKwargDefault,
compat: CompatOptions | CombineKwargDefault,
positions: Iterable[Iterable[int]] | None,
fill_value: object,
join: JoinOptions | CombineKwargDefault,
combine_attrs: CombineAttrsOptions,
create_index_for_new_dim: bool,
)
| 864 | |
| 865 | |
| 866 | def _dataarray_concat( |
| 867 | arrays: Iterable[T_DataArray], |
| 868 | dim: Hashable | T_Variable | T_DataArray | pd.Index, |
| 869 | data_vars: T_DataVars | Iterable[Hashable] | CombineKwargDefault, |
| 870 | coords: ConcatOptions | Iterable[Hashable] | CombineKwargDefault, |
| 871 | compat: CompatOptions | CombineKwargDefault, |
| 872 | positions: Iterable[Iterable[int]] | None, |
| 873 | fill_value: object, |
| 874 | join: JoinOptions | CombineKwargDefault, |
| 875 | combine_attrs: CombineAttrsOptions, |
| 876 | create_index_for_new_dim: bool, |
| 877 | ) -> T_DataArray: |
| 878 | from xarray.core.dataarray import DataArray |
| 879 | |
| 880 | arrays = list(arrays) |
| 881 | |
| 882 | if not all(isinstance(array, DataArray) for array in arrays): |
| 883 | raise TypeError( |
| 884 | "The elements in the input list need to be either all 'Dataset's or all 'DataArray's" |
| 885 | ) |
| 886 | |
| 887 | # Allow passing `all` or `None` even though we always use `data_vars='all'` |
| 888 | # when passing off to `_dataset_concat`. |
| 889 | if not isinstance(data_vars, CombineKwargDefault) and data_vars not in [ |
| 890 | "all", |
| 891 | None, |
| 892 | ]: |
| 893 | raise ValueError( |
| 894 | "data_vars is not a valid argument when concatenating DataArray objects" |
| 895 | ) |
| 896 | |
| 897 | datasets = [] |
| 898 | for n, arr in enumerate(arrays): |
| 899 | if n == 0: |
| 900 | name = arr.name |
| 901 | elif name != arr.name: |
| 902 | if compat == "identical": |
| 903 | raise ValueError("array names not identical") |
| 904 | else: |
| 905 | arr = arr.rename(name) |
| 906 | datasets.append(arr._to_temp_dataset()) |
| 907 | |
| 908 | ds = _dataset_concat( |
| 909 | datasets, |
| 910 | dim=dim, |
| 911 | data_vars="all", |
| 912 | coords=coords, |
| 913 | compat=compat, |
| 914 | positions=positions, |
| 915 | fill_value=fill_value, |
| 916 | join=join, |
| 917 | combine_attrs=combine_attrs, |
| 918 | create_index_for_new_dim=create_index_for_new_dim, |
| 919 | ) |
| 920 | |
| 921 | merged_attrs = merge_attrs([da.attrs for da in arrays], combine_attrs) |
| 922 | |
| 923 | result = arrays[0]._from_temp_dataset(ds, name) |
no test coverage detected
searching dependent graphs…