Skip to content
This repository was archived by the owner on Oct 24, 2024. It is now read-only.
This repository was archived by the owner on Oct 24, 2024. It is now read-only.

Typing issue: Pylance complains with DataTree inequalities #323

@louisletoumelin

Description

@louisletoumelin

Hello,

I encountered the following typing issue: inequality between a datatree instance and a float raises a Pylance issue.

datatree version: 0.0.14

Reproducing the warning

I use the datatree example from the Quick Overview section in the doc (https://xarray-datatree.readthedocs.io/en/latest/quick-overview.html)

from datatree import DataTree

data = xr.DataArray(np.random.randn(2, 3), dims=("x", "y"), coords={"x": [10, 20]})
ds = xr.Dataset(dict(foo=data, bar=("x", [1, 2]), baz=np.pi))
ds2 = ds.interp(coords={"x": [10, 12, 14, 16, 18, 20]})
ds3 = xr.Dataset(
    dict(people=["alice", "bob"], heights=("people", [1.57, 1.82])),
    coords={"species": "human"},
)
dt = DataTree.from_dict({"simulation/coarse": ds, "simulation/fine": ds2, "/": ds3})

Then,

dt > 3.0  # works but Pylance complains: Operator ">" not supported for types "DataTree[Unknown]" and "float" PylancereportOperatorIssue
dt < 3.0 # works but Pylance complains: Operator "<" not supported for types "DataTree[Unknown]" and "float" PylancereportOperatorIssue
dt <= 3.0 # works but Pylance complains: Operator "<=" not supported for types "DataTree[Unknown]" and "float" PylancereportOperatorIssue
dt >= 3.0 # works but Pylance complains: Operator ">=" not supported for types "DataTree[Unknown]" and "float" PylancereportOperatorIssue
dt == 3  # Works fine. No Pylance issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions