MCPcopy
hub / github.com/pydata/xarray / _dataset_concat

Function _dataset_concat

xarray/structure/concat.py:605–863  ·  view source on GitHub ↗

Concatenate a sequence of datasets along a new or existing dimension

(
    datasets: Iterable[T_Dataset],
    dim: Hashable | T_Variable | T_DataArray | pd.Index,
    data_vars: T_DataVars | CombineKwargDefault,
    coords: ConcatOptions | Iterable[Hashable] | CombineKwargDefault,
    compat: CompatOptions | CombineKwargDefault,
    positions: Iterable[Iterable[int]] | None,
    fill_value: Any,
    join: JoinOptions | CombineKwargDefault,
    combine_attrs: CombineAttrsOptions,
    create_index_for_new_dim: bool,
    *,
    preexisting_dim: bool = False,
)

Source from the content-addressed store, hash-verified

603
604
605def _dataset_concat(
606 datasets: Iterable[T_Dataset],
607 dim: Hashable | T_Variable | T_DataArray | pd.Index,
608 data_vars: T_DataVars | CombineKwargDefault,
609 coords: ConcatOptions | Iterable[Hashable] | CombineKwargDefault,
610 compat: CompatOptions | CombineKwargDefault,
611 positions: Iterable[Iterable[int]] | None,
612 fill_value: Any,
613 join: JoinOptions | CombineKwargDefault,
614 combine_attrs: CombineAttrsOptions,
615 create_index_for_new_dim: bool,
616 *,
617 preexisting_dim: bool = False,
618) -> T_Dataset:
619 """
620 Concatenate a sequence of datasets along a new or existing dimension
621 """
622 from xarray.core.dataarray import DataArray
623 from xarray.core.dataset import Dataset
624
625 datasets = list(datasets)
626
627 if not all(isinstance(dataset, Dataset) for dataset in datasets):
628 raise TypeError(
629 "The elements in the input list need to be either all 'Dataset's or all 'DataArray's"
630 )
631
632 dim_var: Variable | None
633 if isinstance(dim, DataArray):
634 dim_var = dim.variable
635 elif isinstance(dim, Variable):
636 dim_var = dim
637 else:
638 dim_var = None
639
640 dim_name, index = _calc_concat_dim_index(dim)
641
642 # Make sure we're working on a copy (we'll be loading variables)
643 datasets = [ds.copy() for ds in datasets]
644 datasets = list(
645 align(
646 *datasets, join=join, copy=False, exclude=[dim_name], fill_value=fill_value
647 )
648 )
649
650 all_dims, dim_coords, dims_sizes, coord_names, data_names, vars_order = (
651 _parse_datasets(datasets)
652 )
653 if preexisting_dim:
654 # When concatenating DataTree objects, a dimension may be pre-existing
655 # because it exists elsewhere on the trees, even if it does not exist
656 # on the dataset objects at this node.
657 all_dims.add(dim_name)
658 indexed_dim_names = set(dim_coords)
659
660 both_data_and_coords = coord_names & data_names
661 if both_data_and_coords:
662 raise ValueError(

Callers 3

concatFunction · 0.85
_dataarray_concatFunction · 0.85
_datatree_concatFunction · 0.85

Calls 15

alignFunction · 0.90
merge_collectedFunction · 0.90
merge_attrsFunction · 0.90
reindex_variablesFunction · 0.90
CoordinatesClass · 0.90
_calc_concat_dim_indexFunction · 0.85
_parse_datasetsFunction · 0.85
_calc_concat_overFunction · 0.85
ensure_common_dimsFunction · 0.85
get_indexesFunction · 0.85
typeFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…