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

Conversation

TomNicholas
Copy link
Member

@TomNicholas TomNicholas commented Jun 23, 2021

Added type hints to combine_nested and combine_by_coords.

Builds on #4696 because that PR generalised the argument types to include DataArrays, but I couldn't see that branch in the list to base this PR off of.

The "nested list-of-lists" argument to combine_nested opens up a can of worms: the only way I can see to specify the type of a nested list of arbitrary depth is to define the type recursively, but mypy does not currently support recursive type definitions, though some other type checkers can, e.g. Microsoft's Pylance does. We're going to have the same problem when specifying types for open_mfdataset. For now this problem is just ignored by the type checker, meaning that we don't actually check the type of the nested-list-of-lists.

  • Passes pre-commit run --all-files
  • User visible changes (including notable bug fixes) are documented in whats-new.rst

…converter to combine_by_coords to check for all DataArray case and convert to datasets.
…rrays and dataset input and with empty list.
Comment on lines +359 to +361
# 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
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

@TomNicholas
Copy link
Member Author

(It does pass pre-commit locally, the linting failures in the CI are due to #5517)

@github-actions
Copy link
Contributor

github-actions bot commented Jul 2, 2021

Unit Test Results

         6 files  ±0           6 suites  ±0   53m 35s ⏱️ ±0s
16 228 tests ±0  14 494 ✔️ ±0  1 734 💤 ±0  0 ±0 
90 564 runs  ±0  82 385 ✔️ ±0  8 179 💤 ±0  0 ±0 

Results for commit 043d68b. ± Comparison against base commit 043d68b.

♻️ This comment has been updated with latest results.

@max-sixty max-sixty added the plan to merge Final call for comments label Jul 2, 2021
@max-sixty
Copy link
Collaborator

Thanks @TomNicholas !

@max-sixty
Copy link
Collaborator

@TomNicholas given the upstream changes, should we merge main in first and then merge?

@TomNicholas TomNicholas merged commit 043d68b into pydata:main Sep 30, 2021
snowman2 pushed a commit to snowman2/xarray that referenced this pull request Feb 9, 2022
* Added test for combine_by_coords changes.

* Modified test case to expect a dataset instead of a DataArray. Added converter to combine_by_coords to check for all DataArray case and convert to datasets.

* Added tests to check combine_by_coords for exception with mixed DataArrays and dataset input and with empty list.

* Formatting changes after running black

* Added underscore to helper function to label as private.

* Black formatting changes for whats-new doc file.

* Removed imports in docstring that were automatically added by code styling tools to match the other docstrings.

* Removed duplicate new item line in whats-new.

* combine methods now accept unnamed DataArrays as input.

* combine nested test checks nested lists of unnamed DataArrays.

* Made combine_by_coords more readable.

* Cosmetic changes to code style.

* Removed extra test from merge with previous PR.

* Updated test to use pytest.raises instead of raises_regex.

* Added breaking-change entry to whats new page.

* Added deprecation warning to combine_coords

* Removed index monotonicity checking temporarily.

* Removed duplicate entries from whats new page.

* Removed TODO message

* Added test for combine_nested.

* Added check to combine methods to clarify parameter requirements.

* Reassigned description of changes to bug fixes category.

* Minor style changes.

* Added blank line for style purposes.

* added type hints

* force CI

Co-authored-by: Augustus Ijams <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
plan to merge Final call for comments
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants