xarray-contrib / datatree

WIP implementation of a tree-like hierarchical data structure for xarray.
https://xarray-datatree.readthedocs.io
Apache License 2.0
161 stars 43 forks source link

Typing issue: Pylance complains with DataTree inequalities #323

Open louisletoumelin opened 3 months ago

louisletoumelin commented 3 months ago

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 commented 2 months ago

maybe related to #313