|
1 | 1 | import itertools
|
2 | 2 | import warnings
|
3 | 3 | from collections import Counter
|
| 4 | +from typing import Iterable, Sequence, Union |
4 | 5 |
|
5 | 6 | import pandas as pd
|
6 | 7 |
|
@@ -369,16 +370,23 @@ def _nested_combine(
|
369 | 370 | return combined
|
370 | 371 |
|
371 | 372 |
|
| 373 | +# Define type for arbitrarily-nested list of lists recursively |
| 374 | +# Currently mypy cannot handle this but other linters can (https://stackoverflow.com/a/53845083/3154101) |
| 375 | +DATASET_HYPERCUBE = Union[Dataset, Iterable["DATASET_HYPERCUBE"]] # type: ignore |
| 376 | + |
| 377 | + |
372 | 378 | def combine_nested(
|
373 |
| - datasets, |
374 |
| - concat_dim, |
375 |
| - compat="no_conflicts", |
376 |
| - data_vars="all", |
377 |
| - coords="different", |
378 |
| - fill_value=dtypes.NA, |
379 |
| - join="outer", |
380 |
| - combine_attrs="drop", |
381 |
| -): |
| 379 | + datasets: DATASET_HYPERCUBE, |
| 380 | + concat_dim: Union[ |
| 381 | + str, DataArray, None, Sequence[Union[str, "DataArray", pd.Index, None]] |
| 382 | + ], |
| 383 | + compat: str = "no_conflicts", |
| 384 | + data_vars: str = "all", |
| 385 | + coords: str = "different", |
| 386 | + fill_value: object = dtypes.NA, |
| 387 | + join: str = "outer", |
| 388 | + combine_attrs: str = "drop", |
| 389 | +) -> Dataset: |
382 | 390 | """
|
383 | 391 | Explicitly combine an N-dimensional grid of datasets into one by using a
|
384 | 392 | succession of concat and merge operations along each dimension of the grid.
|
@@ -651,16 +659,17 @@ def _combine_single_variable_hypercube(
|
651 | 659 |
|
652 | 660 | # TODO remove empty list default param after version 0.21, see PR4696
|
653 | 661 | def combine_by_coords(
|
654 |
| - data_objects=[], |
655 |
| - compat="no_conflicts", |
656 |
| - data_vars="all", |
657 |
| - coords="different", |
658 |
| - fill_value=dtypes.NA, |
659 |
| - join="outer", |
660 |
| - combine_attrs="no_conflicts", |
661 |
| - datasets=None, |
662 |
| -): |
| 662 | + data_objects: Sequence[Union[Dataset, DataArray]] = [], |
| 663 | + compat: str = "no_conflicts", |
| 664 | + data_vars: str = "all", |
| 665 | + coords: str = "different", |
| 666 | + fill_value: object = dtypes.NA, |
| 667 | + join: str = "outer", |
| 668 | + combine_attrs: str = "no_conflicts", |
| 669 | + datasets: Sequence[Dataset] = None, |
| 670 | +) -> Union[Dataset, DataArray]: |
663 | 671 | """
|
| 672 | +
|
664 | 673 | Attempt to auto-magically combine the given datasets (or data arrays)
|
665 | 674 | into one by using dimension coordinates.
|
666 | 675 |
|
@@ -755,7 +764,7 @@ def combine_by_coords(
|
755 | 764 |
|
756 | 765 | Returns
|
757 | 766 | -------
|
758 |
| - combined : xarray.Dataset |
| 767 | + combined : xarray.Dataset or xarray.DataArray |
759 | 768 |
|
760 | 769 | See also
|
761 | 770 | --------
|
|
0 commit comments