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

Typing issue: Pylance complains with DataTree inequalities #323

Closed
louisletoumelin opened this issue Mar 14, 2024 · 3 comments
Closed

Typing issue: Pylance complains with DataTree inequalities #323

louisletoumelin opened this issue Mar 14, 2024 · 3 comments

Comments

@louisletoumelin
Copy link

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.
@eschalkargans
Copy link

maybe related to #313

@TomNicholas
Copy link
Member

Does this problem still exist after pydata/xarray#9445?

@TomNicholas
Copy link
Member

This was probably fixed by pydata/xarray#9445, can re-open upstream if not.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants