Skip to content

Commit

Permalink
Update pyproject.toml to exclude imported datatree_ modules.
Browse files Browse the repository at this point in the history
Add some typing for mygrated tests.
Adds display_expand_groups to core options.
  • Loading branch information
flamingbear committed Feb 5, 2024
1 parent 3c5bcda commit 9f89256
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 9 deletions.
5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ warn_redundant_casts = true
warn_unused_configs = true
warn_unused_ignores = true

# Ignore mypy errors for modules imported from datatree_.
[[tool.mypy.overrides]]
module = "xarray.datatree_.*"
ignore_errors = true

# Much of the numerical computing stack doesn't have type annotations yet.
[[tool.mypy.overrides]]
ignore_missing_imports = true
Expand Down
3 changes: 3 additions & 0 deletions xarray/core/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"display_expand_coords",
"display_expand_data_vars",
"display_expand_data",
"display_expand_groups",
"display_expand_indexes",
"display_default_indexes",
"enable_cftimeindex",
Expand All @@ -44,6 +45,7 @@ class T_Options(TypedDict):
display_expand_coords: Literal["default", True, False]
display_expand_data_vars: Literal["default", True, False]
display_expand_data: Literal["default", True, False]
display_expand_groups: Literal["default", True, False]
display_expand_indexes: Literal["default", True, False]
display_default_indexes: Literal["default", True, False]
enable_cftimeindex: bool
Expand All @@ -68,6 +70,7 @@ class T_Options(TypedDict):
"display_expand_coords": "default",
"display_expand_data_vars": "default",
"display_expand_data": "default",
"display_expand_groups": "default",
"display_expand_indexes": "default",
"display_default_indexes": False,
"enable_cftimeindex": True,
Expand Down
3 changes: 2 additions & 1 deletion xarray/datatree_/datatree/datatree.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
List,
Mapping,
MutableMapping,
NoReturn,
Optional,
Set,
Tuple,
Expand Down Expand Up @@ -160,7 +161,7 @@ def __setitem__(self, key, val) -> None:
"use `.copy()` first to get a mutable version of the input dataset."
)

def update(self, other) -> None:
def update(self, other) -> NoReturn:
raise AttributeError(
"Mutation of the DatasetView is not allowed, please use `.update` on the wrapping DataTree node, "
"or use `dt.to_dataset()` if you want a mutable dataset. If calling this from within `map_over_subtree`,"
Expand Down
3 changes: 0 additions & 3 deletions xarray/datatree_/datatree/formatting_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
datavar_section,
dim_section,
)
from xarray.core.options import OPTIONS

OPTIONS["display_expand_groups"] = "default"


def summarize_children(children: Mapping[str, Any]) -> str:
Expand Down
6 changes: 3 additions & 3 deletions xarray/tests/datatree/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ def _create_test_datatree(modify=lambda ds: ds):
root_data = modify(xr.Dataset({"a": ("y", [6, 7, 8]), "set0": ("x", [9, 10])}))

# Avoid using __init__ so we can independently test it
root = DataTree(data=root_data)
set1 = DataTree(name="set1", parent=root, data=set1_data)
root: DataTree = DataTree(data=root_data)
set1: DataTree = DataTree(name="set1", parent=root, data=set1_data)
DataTree(name="set1", parent=set1)
DataTree(name="set2", parent=set1)
set2 = DataTree(name="set2", parent=root, data=set2_data)
set2: DataTree = DataTree(name="set2", parent=root, data=set2_data)
DataTree(name="set1", parent=set2)
DataTree(name="set3", parent=root)

Expand Down
4 changes: 2 additions & 2 deletions xarray/tests/datatree/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def test_netcdf_encoding(self, tmpdir, simple_datatree):
assert roundtrip_dt["/set2/a"].encoding["zlib"] == comp["zlib"]
assert roundtrip_dt["/set2/a"].encoding["complevel"] == comp["complevel"]

enc["/not/a/group"] = {"foo": "bar"}
enc["/not/a/group"] = {"foo": "bar"} # type: ignore
with pytest.raises(ValueError, match="unexpected encoding group.*"):
original_dt.to_netcdf(filepath, encoding=enc, engine="netcdf4")

Expand Down Expand Up @@ -81,7 +81,7 @@ def test_zarr_encoding(self, tmpdir, simple_datatree):
print(roundtrip_dt["/set2/a"].encoding)
assert roundtrip_dt["/set2/a"].encoding["compressor"] == comp["compressor"]

enc["/not/a/group"] = {"foo": "bar"}
enc["/not/a/group"] = {"foo": "bar"} # type: ignore
with pytest.raises(ValueError, match="unexpected encoding group.*"):
original_dt.to_zarr(filepath, encoding=enc, engine="zarr")

Expand Down

0 comments on commit 9f89256

Please sign in to comment.