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

Use a bound TypeVar for DataArray and Dataset methods #8208

Closed
wants to merge 6 commits into from

Commits on Sep 19, 2023

  1. Use a bound TypeVar for DataArray and Dataset methods

    I _think_ we should be using a `TypeVar(..., bound=...)` for our typing, since otherwise subtypes aren't allowed. I don't see a compelling reason to have both, though I might be missing something.
    
    So this changes all `T_DataWithCoords` to `T_Xarray`, and changes that type to bound on a union of `DataArray` & `Dataset`. This covers the bulk of the API which offer transformations of either a `DataArray` or `Dataset` and return that object.
    
    This does require some manual casts; I think because when there's a concrete path for both `DataArray` & `Dataset`, mypy doesn't unify them back together. It's also possible I'm missing something.
    
    One alternative — a minor change — would be to bound on `DataWithCoords`, rather than the union. A quick comparison showed both required some casts / ignores.
    max-sixty committed Sep 19, 2023
    Configuration menu
    Copy the full SHA
    6177f6d View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    ea72ad7 View commit details
    Browse the repository at this point in the history
  3. No commit message

    max-sixty committed Sep 19, 2023
    Configuration menu
    Copy the full SHA
    897e8e0 View commit details
    Browse the repository at this point in the history
  4. No commit message

    max-sixty committed Sep 19, 2023
    Configuration menu
    Copy the full SHA
    1ab9210 View commit details
    Browse the repository at this point in the history
  5. No commit message

    max-sixty committed Sep 19, 2023
    Configuration menu
    Copy the full SHA
    e1c3df1 View commit details
    Browse the repository at this point in the history
  6. Update xarray/core/common.py

    Co-authored-by: Michael Niklas  <mick.niklas@gmail.com>
    max-sixty and headtr1ck committed Sep 19, 2023
    Configuration menu
    Copy the full SHA
    ef42745 View commit details
    Browse the repository at this point in the history