Skip to content
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

Typing annotations for arithmetic overrides (e.g., DataArray + Dataset) #9688

Merged
merged 3 commits into from
Oct 28, 2024

Conversation

shoyer
Copy link
Member

@shoyer shoyer commented Oct 28, 2024

This change explicitly adds annotations for arithmetic like DataArray + Dataset in _typed_ops.py.

To test this, I've updated mypy on GitHub actions to use Python 3.12

Note: I've added a dependency on jinja2, a standard Python templating engine. It is only required for manually regenerating typed operations, which should impact only a handful of xarray developers.

This change explicitly adds annotations for arithmetic like
DataArray + Dataset in `_typed_ops.py`.

Note: I've added a dependency on jinja2, a standard Python templating
engine. It is only required for manually regenerating typed operations,
which should impact only a handful of xarray developers.

Fixes GH9656
Copy link
Collaborator

@max-sixty max-sixty left a comment

Choose a reason for hiding this comment

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

Looks good!

Any chance we can add jinja2 to the dev dependencies in pyproject.toml? Or I can do it at some point. (and if we have an equivalent for conda). That way, our instructions for generating these remain valid.

@shoyer
Copy link
Member Author

shoyer commented Oct 28, 2024

Any chance we can add jinja2 to the dev dependencies in pyproject.toml? Or I can do it at some point. (and if we have an equivalent for conda). That way, our instructions for generating these remain valid.

Done!

@shoyer shoyer merged commit 88612ce into pydata:main Oct 28, 2024
29 checks passed
@shoyer shoyer deleted the typing-overloads branch October 28, 2024 22:44
dcherian added a commit to dcherian/xarray that referenced this pull request Oct 29, 2024
* main:
  Add `DataTree.persist` (pydata#9682)
  Typing annotations for arithmetic overrides (e.g., DataArray + Dataset) (pydata#9688)
  Raise `ValueError` for unmatching chunks length in `DataArray.chunk()` (pydata#9689)
  Fix inadvertent deep-copying of child data in DataTree (pydata#9684)
  new blank whatsnew (pydata#9679)
  v2024.10.0 release summary (pydata#9678)
  drop the length from `numpy`'s fixed-width string dtypes (pydata#9586)
  fixing behaviour for group parameter in `open_datatree` (pydata#9666)
  Use zarr v3 dimension_names (pydata#9669)
  fix(zarr): use inplace array.resize for zarr 2 and 3 (pydata#9673)
  implement `dask` methods on `DataTree` (pydata#9670)
  support `chunks` in `open_groups` and `open_datatree` (pydata#9660)
  Compatibility for zarr-python 3.x (pydata#9552)
  Update to_dataframe doc to match current behavior (pydata#9662)
  Reduce graph size through writing indexes directly into graph for ``map_blocks`` (pydata#9658)
dcherian added a commit to dcherian/xarray that referenced this pull request Nov 3, 2024
* main: (85 commits)
  Refactor out utility functions from to_zarr (pydata#9695)
  Use the same function to floatize coords in polyfit and polyval (pydata#9691)
  Add `DataTree.persist` (pydata#9682)
  Typing annotations for arithmetic overrides (e.g., DataArray + Dataset) (pydata#9688)
  Raise `ValueError` for unmatching chunks length in `DataArray.chunk()` (pydata#9689)
  Fix inadvertent deep-copying of child data in DataTree (pydata#9684)
  new blank whatsnew (pydata#9679)
  v2024.10.0 release summary (pydata#9678)
  drop the length from `numpy`'s fixed-width string dtypes (pydata#9586)
  fixing behaviour for group parameter in `open_datatree` (pydata#9666)
  Use zarr v3 dimension_names (pydata#9669)
  fix(zarr): use inplace array.resize for zarr 2 and 3 (pydata#9673)
  implement `dask` methods on `DataTree` (pydata#9670)
  support `chunks` in `open_groups` and `open_datatree` (pydata#9660)
  Compatibility for zarr-python 3.x (pydata#9552)
  Update to_dataframe doc to match current behavior (pydata#9662)
  Reduce graph size through writing indexes directly into graph for ``map_blocks`` (pydata#9658)
  Add close() method to DataTree and use it to clean-up open files in tests (pydata#9651)
  Change URL for pydap test (pydata#9655)
  Fix multiple grouping with missing groups (pydata#9650)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

mypy failure for Variable + Dataset arithmetic in test_typed_ops.py with Python 3.12 only
2 participants