Skip to content

Type hints for combine functions #5519

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 41 commits into from
Sep 30, 2021
Merged
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
b35de8e
Added test for combine_by_coords changes.
aijams Dec 10, 2020
f966e76
Modified test case to expect a dataset instead of a DataArray. Added …
aijams Dec 11, 2020
68b7b49
Added tests to check combine_by_coords for exception with mixed DataA…
aijams Dec 12, 2020
540961f
Formatting changes after running black
aijams Dec 15, 2020
1c9b4c2
Added underscore to helper function to label as private.
aijams Dec 15, 2020
cb5ed5e
Black formatting changes for whats-new doc file.
aijams Dec 15, 2020
77020c0
Removed imports in docstring that were automatically added by code st…
aijams Dec 17, 2020
6af896b
Merge branch 'master' into aijams/combine-by-coords
aijams Dec 17, 2020
f06371a
Merge remote-tracking branch 'upstream/master' into aijams/combine-by…
aijams Dec 19, 2020
7cdeabb
Merge branch 'aijams/combine-by-coords' of https://github.com/aijams/…
aijams Dec 19, 2020
6190839
Removed duplicate new item line in whats-new.
aijams Dec 19, 2020
3055000
Merge remote-tracking branch 'upstream/master' into aijams/combine-by…
aijams Jan 30, 2021
cbc002f
combine methods now accept unnamed DataArrays as input.
aijams Apr 15, 2021
11a868b
Merge remote-tracking branch 'upstream/master' into aijams/combine-by…
aijams Apr 15, 2021
89ac962
combine nested test checks nested lists of unnamed DataArrays.
aijams Apr 15, 2021
5f3afa5
Made combine_by_coords more readable.
aijams Apr 15, 2021
feb90ce
Cosmetic changes to code style.
aijams Apr 15, 2021
db5b906
Merging changes from first PR.
aijams Apr 18, 2021
e884f52
Merge remote-tracking branch 'upstream/master' into aijams/combine-by…
aijams Apr 18, 2021
0044bb9
Removed extra test from merge with previous PR.
aijams Apr 18, 2021
44548ee
Merge remote-tracking branch 'upstream/master' into aijams/combine-by…
aijams May 4, 2021
5fe8323
Updated test to use pytest.raises instead of raises_regex.
aijams May 4, 2021
55f53b9
Merged latests changes from upstream.
aijams May 10, 2021
805145c
Added breaking-change entry to whats new page.
aijams May 11, 2021
3eed47a
Merged new changes from master branch.
aijams May 11, 2021
05faa88
Added deprecation warning to combine_coords
aijams May 11, 2021
6c75525
Removed index monotonicity checking temporarily.
aijams May 11, 2021
2c43030
Removed duplicate entries from whats new page.
aijams May 12, 2021
f6fae25
Removed TODO message
aijams May 12, 2021
81ec1ff
Added test for combine_nested.
aijams May 16, 2021
caaee74
Merge remote-tracking branch 'upstream/master' into aijams/combine-by…
aijams May 16, 2021
637d4cc
Added check to combine methods to clarify parameter requirements.
aijams May 16, 2021
b5940a1
Reassigned description of changes to bug fixes category.
aijams May 19, 2021
d02da23
Merge remote-tracking branch 'upstream/master' into aijams/combine-by…
aijams May 19, 2021
04cd5f8
Minor style changes.
aijams May 19, 2021
e58a9e2
Added blank line for style purposes.
aijams May 19, 2021
c0fc4f1
Merge remote-tracking branch 'upstream/master' into aijams/combine-by…
aijams Jun 10, 2021
82e47fd
added type hints
TomNicholas Jun 23, 2021
78d6a5f
force CI
TomNicholas Jul 2, 2021
100f3ea
merge main
TomNicholas Jul 2, 2021
2cd5a5d
Merge branch 'main' into combine_typing
TomNicholas Sep 30, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 28 additions & 19 deletions xarray/core/combine.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import itertools
import warnings
from collections import Counter
from typing import Iterable, Sequence, Union

import pandas as pd

Expand Down Expand Up @@ -369,16 +370,23 @@ def _nested_combine(
return combined


# Define type for arbitrarily-nested list of lists recursively
# Currently mypy cannot handle this but other linters can (https://stackoverflow.com/a/53845083/3154101)
DATASET_HYPERCUBE = Union[Dataset, Iterable["DATASET_HYPERCUBE"]] # type: ignore
Comment on lines +373 to +375
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The weird recursive definition is here



def combine_nested(
datasets,
concat_dim,
compat="no_conflicts",
data_vars="all",
coords="different",
fill_value=dtypes.NA,
join="outer",
combine_attrs="drop",
):
datasets: DATASET_HYPERCUBE,
concat_dim: Union[
str, DataArray, None, Sequence[Union[str, "DataArray", pd.Index, None]]
],
compat: str = "no_conflicts",
data_vars: str = "all",
coords: str = "different",
fill_value: object = dtypes.NA,
join: str = "outer",
combine_attrs: str = "drop",
) -> Dataset:
"""
Explicitly combine an N-dimensional grid of datasets into one by using a
succession of concat and merge operations along each dimension of the grid.
Expand Down Expand Up @@ -651,16 +659,17 @@ def _combine_single_variable_hypercube(

# TODO remove empty list default param after version 0.21, see PR4696
def combine_by_coords(
data_objects=[],
compat="no_conflicts",
data_vars="all",
coords="different",
fill_value=dtypes.NA,
join="outer",
combine_attrs="no_conflicts",
datasets=None,
):
data_objects: Sequence[Union[Dataset, DataArray]] = [],
compat: str = "no_conflicts",
data_vars: str = "all",
coords: str = "different",
fill_value: object = dtypes.NA,
join: str = "outer",
combine_attrs: str = "no_conflicts",
datasets: Sequence[Dataset] = None,
) -> Union[Dataset, DataArray]:
"""

Attempt to auto-magically combine the given datasets (or data arrays)
into one by using dimension coordinates.

Expand Down Expand Up @@ -755,7 +764,7 @@ def combine_by_coords(

Returns
-------
combined : xarray.Dataset
combined : xarray.Dataset or xarray.DataArray

See also
--------
Expand Down