datatree
datatree copied to clipboard
Typing issue: Pylance complains with DataTree inequalities
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.
maybe related to #313
Does this problem still exist after https://github.com/pydata/xarray/pull/9445?