Skip to content

Commit 0f9c57e

Browse files
committed
fix typing
1 parent f46d584 commit 0f9c57e

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

cf_xarray/accessor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ def _get_coords(obj: DataArray | Dataset, key: Hashable) -> list[Hashable]:
437437
def _variables(func: F) -> F:
438438
@functools.wraps(func)
439439
def wrapper(obj: DataArray | Dataset, key: Hashable) -> list[DataArray]:
440-
return [obj[k] for k in func(obj, key)] # type: ignore
440+
return [obj[k] for k in func(obj, key)]
441441

442442
return cast(F, wrapper)
443443

cf_xarray/formatting.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import warnings
2+
from typing import Dict, Hashable, Iterable, List
23

34
STAR = " * "
45
TAB = len(STAR) * " "
@@ -11,7 +12,7 @@ def _format_missing_row(row: str, rich: bool) -> str:
1112
return row
1213

1314

14-
def _format_varname(name: str, rich: bool) -> str:
15+
def _format_varname(name, rich: bool):
1516
return name
1617

1718

@@ -39,12 +40,14 @@ def make_text_section(
3940
rich: bool = False,
4041
):
4142

43+
from .accessor import sort_maybe_hashable
44+
4245
if dims is None:
4346
dims = []
4447
with warnings.catch_warnings():
4548
warnings.simplefilter("ignore")
4649
try:
47-
vardict = getattr(accessor, attr, {})
50+
vardict: Dict[str, Iterable[Hashable]] = getattr(accessor, attr, {})
4851
except ValueError:
4952
vardict = {}
5053

@@ -67,7 +70,8 @@ def make_text_section(
6770
rows = [
6871
(
6972
f"{STAR if dims and set(value) <= set(dims) else TAB}"
70-
f"{_format_cf_name(key, rich)}: {_format_varname(sorted(value), rich)}"
73+
f"{_format_cf_name(key, rich)}: "
74+
f"{_format_varname(sort_maybe_hashable(value), rich)}"
7175
)
7276
for key, value in vardict.items()
7377
]
@@ -85,7 +89,7 @@ def make_text_section(
8589
return _print_rows(subtitle, rows, rich)
8690

8791

88-
def _print_rows(subtitle: str, rows: list[str], rich: bool):
92+
def _print_rows(subtitle: str, rows: List[str], rich: bool):
8993
subtitle = f"{subtitle.rjust(20)}:"
9094

9195
# Add subtitle to the first row, align other rows

cf_xarray/tests/test_accessor.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ def test_accessor_getattr_and_describe() -> None:
297297
"areacella",
298298
)
299299
)
300-
ds_vertb = xr.decode_cf(vert, decode_coords="all") # type: ignore
300+
ds_vertb = xr.decode_cf(vert, decode_coords="all")
301301

302302
assert ds_verta.cf.cell_measures == ds_vertb.cf.cell_measures
303303
assert ds_verta.o3.cf.cell_measures == ds_vertb.o3.cf.cell_measures
@@ -821,7 +821,7 @@ def test_add_bounds_nd_variable() -> None:
821821
# 2D
822822
expected = (
823823
vertices_to_bounds(
824-
np.arange(0, 13, 3).reshape(5, 1) + np.arange(-2, 2).reshape(1, 4) # type: ignore
824+
np.arange(0, 13, 3).reshape(5, 1) + np.arange(-2, 2).reshape(1, 4)
825825
)
826826
.rename("z_bounds")
827827
.assign_coords(**ds.coords)
@@ -1358,7 +1358,7 @@ def test_new_standard_name_mappers() -> None:
13581358
)
13591359
assert_identical(forecast.cf.chunk({"realization": 1}), forecast.chunk({"M": 1}))
13601360
assert_identical(forecast.cf.isel({"realization": 1}), forecast.isel({"M": 1}))
1361-
assert_identical(forecast.cf.isel(**{"realization": 1}), forecast.isel(**{"M": 1})) # type: ignore
1361+
assert_identical(forecast.cf.isel(**{"realization": 1}), forecast.isel(**{"M": 1}))
13621362
assert_identical(
13631363
forecast.cf.groupby("forecast_reference_time.month").mean(),
13641364
forecast.groupby("S.month").mean(),

0 commit comments

Comments
 (0)