From 2bb86955c02ca996d01545ff4051e8dc467efb45 Mon Sep 17 00:00:00 2001 From: Maximilian Roos Date: Tue, 28 Oct 2025 11:58:17 -0700 Subject: [PATCH 1/2] Fix mypy type checking errors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add type ignore comments for three mypy errors that appeared with updated type stubs: - CFTimeIndex.__add__ and __radd__ have simpler signatures than pandas Index - numpy dtype_out.type() call is valid but flagged by mypy stubs - Remove unused type ignore comment in test_plot.py 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- xarray/coding/cftimeindex.py | 4 ++-- xarray/namedarray/dtypes.py | 2 +- xarray/tests/test_plot.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/xarray/coding/cftimeindex.py b/xarray/coding/cftimeindex.py index b4bde1458b8..c671f0f2c11 100644 --- a/xarray/coding/cftimeindex.py +++ b/xarray/coding/cftimeindex.py @@ -514,12 +514,12 @@ def shift( # type: ignore[override,unused-ignore] f"'freq' must be of type str or datetime.timedelta, got {type(freq)}." ) - def __add__(self, other) -> Self: + def __add__(self, other) -> Self: # type: ignore[override] if isinstance(other, pd.TimedeltaIndex): other = other.to_pytimedelta() return type(self)(np.array(self) + other) - def __radd__(self, other) -> Self: + def __radd__(self, other) -> Self: # type: ignore[override] if isinstance(other, pd.TimedeltaIndex): other = other.to_pytimedelta() return type(self)(other + np.array(self)) diff --git a/xarray/namedarray/dtypes.py b/xarray/namedarray/dtypes.py index b4a3d6a518e..9dc9aff617a 100644 --- a/xarray/namedarray/dtypes.py +++ b/xarray/namedarray/dtypes.py @@ -83,7 +83,7 @@ def maybe_promote(dtype: np.dtype[np.generic]) -> tuple[np.dtype[np.generic], An fill_value = np.nan dtype_out = np.dtype(dtype_) - fill_value = dtype_out.type(fill_value) + fill_value = dtype_out.type(fill_value) # type: ignore[call-arg] return dtype_out, fill_value diff --git a/xarray/tests/test_plot.py b/xarray/tests/test_plot.py index 64054bad8ab..60ccf6a915a 100644 --- a/xarray/tests/test_plot.py +++ b/xarray/tests/test_plot.py @@ -529,7 +529,7 @@ def test__infer_interval_breaks(self) -> None: [-0.5, 0.5, 5.0, 9.5, 10.5], _infer_interval_breaks([0, 1, 9, 10]) ) assert_array_equal( - pd.date_range("20000101", periods=4) - np.timedelta64(12, "h"), # type: ignore[operator] + pd.date_range("20000101", periods=4) - np.timedelta64(12, "h"), _infer_interval_breaks(pd.date_range("20000101", periods=3)), ) From 273b9bbd24415077602f32fc367802df76da3793 Mon Sep 17 00:00:00 2001 From: Maximilian Roos Date: Tue, 28 Oct 2025 12:04:21 -0700 Subject: [PATCH 2/2] Fix mypy errors for CI environment MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit CI uses different pandas/numpy type stubs than local environment. Only keep the type: ignore[operator] for test_plot.py that CI needs. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- xarray/coding/cftimeindex.py | 4 ++-- xarray/namedarray/dtypes.py | 2 +- xarray/tests/test_plot.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/xarray/coding/cftimeindex.py b/xarray/coding/cftimeindex.py index c671f0f2c11..b4bde1458b8 100644 --- a/xarray/coding/cftimeindex.py +++ b/xarray/coding/cftimeindex.py @@ -514,12 +514,12 @@ def shift( # type: ignore[override,unused-ignore] f"'freq' must be of type str or datetime.timedelta, got {type(freq)}." ) - def __add__(self, other) -> Self: # type: ignore[override] + def __add__(self, other) -> Self: if isinstance(other, pd.TimedeltaIndex): other = other.to_pytimedelta() return type(self)(np.array(self) + other) - def __radd__(self, other) -> Self: # type: ignore[override] + def __radd__(self, other) -> Self: if isinstance(other, pd.TimedeltaIndex): other = other.to_pytimedelta() return type(self)(other + np.array(self)) diff --git a/xarray/namedarray/dtypes.py b/xarray/namedarray/dtypes.py index 9dc9aff617a..b4a3d6a518e 100644 --- a/xarray/namedarray/dtypes.py +++ b/xarray/namedarray/dtypes.py @@ -83,7 +83,7 @@ def maybe_promote(dtype: np.dtype[np.generic]) -> tuple[np.dtype[np.generic], An fill_value = np.nan dtype_out = np.dtype(dtype_) - fill_value = dtype_out.type(fill_value) # type: ignore[call-arg] + fill_value = dtype_out.type(fill_value) return dtype_out, fill_value diff --git a/xarray/tests/test_plot.py b/xarray/tests/test_plot.py index 60ccf6a915a..64054bad8ab 100644 --- a/xarray/tests/test_plot.py +++ b/xarray/tests/test_plot.py @@ -529,7 +529,7 @@ def test__infer_interval_breaks(self) -> None: [-0.5, 0.5, 5.0, 9.5, 10.5], _infer_interval_breaks([0, 1, 9, 10]) ) assert_array_equal( - pd.date_range("20000101", periods=4) - np.timedelta64(12, "h"), + pd.date_range("20000101", periods=4) - np.timedelta64(12, "h"), # type: ignore[operator] _infer_interval_breaks(pd.date_range("20000101", periods=3)), )