diff --git a/pyproject.toml b/pyproject.toml index 98c3c33aa7b..dd380937bd2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -75,6 +75,8 @@ exclude_lines = ["pragma: no cover", "if TYPE_CHECKING"] exclude = 'xarray/util/generate_.*\.py' files = "xarray" show_error_codes = true +show_error_context = true +warn_redundant_casts = true warn_unused_ignores = true # Most of the numerical computing stack doesn't have type annotations yet. @@ -116,10 +118,6 @@ module = [ "numpy.exceptions.*", # remove once support for `numpy<2.0` has been dropped ] -[[tool.mypy.overrides]] -ignore_errors = true -module = [] - [tool.ruff] builtins = ["ellipsis"] exclude = [ diff --git a/xarray/core/dataarray.py b/xarray/core/dataarray.py index 6dd907a0230..791aad5cd17 100644 --- a/xarray/core/dataarray.py +++ b/xarray/core/dataarray.py @@ -2564,7 +2564,7 @@ def expand_dims( raise ValueError("dims should not contain duplicate values.") dim = dict.fromkeys(dim, 1) elif dim is not None and not isinstance(dim, Mapping): - dim = {cast(Hashable, dim): 1} + dim = {dim: 1} dim = either_dict_or_kwargs(dim, dim_kwargs, "expand_dims") ds = self._to_temp_dataset().expand_dims(dim, axis) @@ -4362,7 +4362,7 @@ def from_series(cls, series: pd.Series, sparse: bool = False) -> DataArray: temp_name = "__temporary_name" df = pd.DataFrame({temp_name: series}) ds = Dataset.from_dataframe(df, sparse=sparse) - result = cast(DataArray, ds[temp_name]) + result = ds[temp_name] result.name = series.name return result diff --git a/xarray/core/dataset.py b/xarray/core/dataset.py index 40ba2677f45..2090a8ef989 100644 --- a/xarray/core/dataset.py +++ b/xarray/core/dataset.py @@ -27,7 +27,7 @@ # remove once numpy 2.0 is the oldest supported version try: - from numpy.exceptions import RankWarning + from numpy.exceptions import RankWarning # type: ignore[attr-defined,unused-ignore] except ImportError: from numpy import RankWarning @@ -447,7 +447,7 @@ def __contains__(self, key: Hashable) -> bool: def __getitem__(self, key: Hashable) -> DataArray: if key not in self._dataset._coord_names: - return cast("DataArray", self._dataset[key]) + return self._dataset[key] raise KeyError(key) def __repr__(self) -> str: diff --git a/xarray/core/nputils.py b/xarray/core/nputils.py index 9efa5824954..c49a06dfc9c 100644 --- a/xarray/core/nputils.py +++ b/xarray/core/nputils.py @@ -8,7 +8,7 @@ # remove once numpy 2.0 is the oldest supported version try: - from numpy.exceptions import RankWarning + from numpy.exceptions import RankWarning # type: ignore[attr-defined,unused-ignore] except ImportError: from numpy import RankWarning diff --git a/xarray/plot/dataarray_plot.py b/xarray/plot/dataarray_plot.py index 54f3c657b6c..8e930d0731c 100644 --- a/xarray/plot/dataarray_plot.py +++ b/xarray/plot/dataarray_plot.py @@ -1052,9 +1052,7 @@ def newplotfunc( else: hueplt_norm_values: list[np.ndarray | None] if hueplt_norm.data is not None: - hueplt_norm_values = list( - cast("DataArray", hueplt_norm.data).to_numpy() - ) + hueplt_norm_values = list(hueplt_norm.data.to_numpy()) else: hueplt_norm_values = [hueplt_norm.data] diff --git a/xarray/tests/test_dataarray.py b/xarray/tests/test_dataarray.py index e8a4259e500..66bc69966d2 100644 --- a/xarray/tests/test_dataarray.py +++ b/xarray/tests/test_dataarray.py @@ -16,7 +16,7 @@ # remove once numpy 2.0 is the oldest supported version try: - from numpy.exceptions import RankWarning + from numpy.exceptions import RankWarning # type: ignore[attr-defined,unused-ignore] except ImportError: from numpy import RankWarning diff --git a/xarray/tests/test_dataset.py b/xarray/tests/test_dataset.py index 1513c6dba94..c832663ecff 100644 --- a/xarray/tests/test_dataset.py +++ b/xarray/tests/test_dataset.py @@ -17,7 +17,7 @@ # remove once numpy 2.0 is the oldest supported version try: - from numpy.exceptions import RankWarning + from numpy.exceptions import RankWarning # type: ignore[attr-defined,unused-ignore] except ImportError: from numpy import RankWarning