home / github / issues

Menu
  • GraphQL API
  • Search all tables

issues: 1962261587

This data as json

id node_id number title user state locked assignee milestone comments created_at updated_at closed_at author_association active_lock_reason draft pull_request body reactions performed_via_github_app state_reason repo type
1962261587 I_kwDOAMm_X8509bxT 8374 Type annotations for Dataset.where and DataArray.where are wrong when subclassed 6665406 closed 0     9 2023-10-25T21:31:02Z 2023-12-05T21:50:49Z 2023-12-05T21:50:48Z NONE      

What is your issue?

I'm aware of the guidance of https://docs.xarray.dev/en/stable/internals/extending-xarray.html to avoid subclassing xarray datastructures, but it doesn't seem to outlaw it altogether, so I figured I'd file this issue anyway.

The type annotations for both Dataset.where and DataArray.where claim that these methods will return the type of Self. In practice, though, if they are called on a subclass of either of these classes, they will actually return instances of either DataArray or Dataset, rather than the subclass.

Here's a trivial demonstration: https://colab.research.google.com/drive/1BiGptVUjyKifFI8PSye4v3ADAMXH6KSZ?usp=sharing

I'm not totally sure what the correct type annotations to add here would be, though. My preferred solution would actually be to make the current type hints correct and return instances of the subclass.

{
    "url": "https://api.github.com/repos/pydata/xarray/issues/8374/reactions",
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  not_planned 13221727 issue

Links from other tables

  • 2 rows from issues_id in issues_labels
  • 0 rows from issue in issue_comments
Powered by Datasette · Queries took 0.794ms · About: xarray-datasette