Skip to content

Commit 175734f

Browse files
max-sixtyclaude
andauthored
Enable mypy checking for test_utils and test_parallelcompat (#10691)
* Enable mypy checking for test_utils and test_parallelcompat Removes xarray.tests.test_utils and xarray.tests.test_parallelcompat from the mypy exclusion list by fixing type issues in these files: - Added type annotations where needed - Added targeted type: ignore comments for intentional test behaviors - Fixed function call signatures to match expected types All tests continue to pass and mypy now checks these files with check_untyped_defs=true. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> * Also enable mypy for test_missing Removes xarray.tests.test_missing from the mypy exclusion list by fixing type issues: - Added type: ignore comments for intentional test cases with invalid methods - Added type annotation for kwargs dict All 115 tests continue to pass. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> --------- Co-authored-by: Claude <[email protected]>
1 parent 278d320 commit 175734f

File tree

4 files changed

+16
-18
lines changed

4 files changed

+16
-18
lines changed

pyproject.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,12 +198,9 @@ module = [
198198
"xarray.tests.test_duck_array_ops",
199199
"xarray.tests.test_indexing",
200200
"xarray.tests.test_merge",
201-
"xarray.tests.test_missing",
202-
"xarray.tests.test_parallelcompat",
203201
"xarray.tests.test_sparse",
204202
"xarray.tests.test_ufuncs",
205203
"xarray.tests.test_units",
206-
"xarray.tests.test_utils",
207204
"xarray.tests.test_variable",
208205
"xarray.tests.test_weighted",
209206
]

xarray/tests/test_missing.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22

33
import itertools
4+
from typing import Any
45
from unittest import mock
56

67
import numpy as np
@@ -204,7 +205,7 @@ def test_interpolate_unsorted_index_raises():
204205
vals = np.array([1, 2, 3], dtype=np.float64)
205206
expected = xr.DataArray(vals, dims="x", coords={"x": [2, 1, 3]})
206207
with pytest.raises(ValueError, match=r"Index 'x' must be monotonically increasing"):
207-
expected.interpolate_na(dim="x", method="index")
208+
expected.interpolate_na(dim="x", method="index") # type: ignore[arg-type]
208209

209210

210211
def test_interpolate_no_dim_raises():
@@ -216,14 +217,14 @@ def test_interpolate_no_dim_raises():
216217
def test_interpolate_invalid_interpolator_raises():
217218
da = xr.DataArray(np.array([1, 2, np.nan, 5], dtype=np.float64), dims="x")
218219
with pytest.raises(ValueError, match=r"not a valid"):
219-
da.interpolate_na(dim="x", method="foo")
220+
da.interpolate_na(dim="x", method="foo") # type: ignore[arg-type]
220221

221222

222223
def test_interpolate_duplicate_values_raises():
223224
data = np.random.randn(2, 3)
224225
da = xr.DataArray(data, coords=[("x", ["a", "a"]), ("y", [0, 1, 2])])
225226
with pytest.raises(ValueError, match=r"Index 'x' has duplicate values"):
226-
da.interpolate_na(dim="x", method="foo")
227+
da.interpolate_na(dim="x", method="foo") # type: ignore[arg-type]
227228

228229

229230
def test_interpolate_multiindex_raises():
@@ -331,15 +332,15 @@ def test_interpolate_limits():
331332
@requires_scipy
332333
def test_interpolate_methods():
333334
for method in ["linear", "nearest", "zero", "slinear", "quadratic", "cubic"]:
334-
kwargs = {}
335+
kwargs: dict[str, Any] = {}
335336
da = xr.DataArray(
336337
np.array([0, 1, 2, np.nan, np.nan, np.nan, 6, 7, 8], dtype=np.float64),
337338
dims="x",
338339
)
339-
actual = da.interpolate_na("x", method=method, **kwargs)
340+
actual = da.interpolate_na("x", method=method, **kwargs) # type: ignore[arg-type]
340341
assert actual.isnull().sum() == 0
341342

342-
actual = da.interpolate_na("x", method=method, limit=2, **kwargs)
343+
actual = da.interpolate_na("x", method=method, limit=2, **kwargs) # type: ignore[arg-type]
343344
assert actual.isnull().sum() == 1
344345

345346

xarray/tests/test_parallelcompat.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def __new__(
4848
def __array_finalize__(self, obj):
4949
if obj is None:
5050
return
51-
self.chunks = getattr(obj, "chunks", None)
51+
self.chunks = getattr(obj, "chunks", None) # type: ignore[assignment]
5252

5353
def rechunk(self, chunks, **kwargs):
5454
copied = self.copy()

xarray/tests/test_utils.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def new_method():
2323
pass
2424

2525
old_method = utils.alias(new_method, "old_method")
26-
assert "deprecated" in old_method.__doc__
26+
assert "deprecated" in old_method.__doc__ # type: ignore[operator]
2727
with pytest.warns(Warning, match="deprecated"):
2828
old_method()
2929

@@ -102,10 +102,10 @@ def test_compat_dict_union(self):
102102
utils.compat_dict_union(self.x, self.z)
103103

104104
def test_dict_equiv(self):
105-
x = {}
105+
x: dict = {}
106106
x["a"] = 3
107107
x["b"] = np.array([1, 2, 3])
108-
y = {}
108+
y: dict = {}
109109
y["b"] = np.array([1.0, 2.0, 3.0])
110110
y["a"] = 3
111111
assert utils.dict_equiv(x, y) # two nparrays are equal
@@ -129,11 +129,11 @@ def test_dict_equiv(self):
129129
def test_frozen(self):
130130
x = utils.Frozen(self.x)
131131
with pytest.raises(TypeError):
132-
x["foo"] = "bar"
132+
x["foo"] = "bar" # type: ignore[index]
133133
with pytest.raises(TypeError):
134-
del x["a"]
134+
del x["a"] # type: ignore[attr-defined]
135135
with pytest.raises(AttributeError):
136-
x.update(self.y)
136+
x.update(self.y) # type: ignore[attr-defined]
137137
assert x.mapping == self.x
138138
assert repr(x) in (
139139
"Frozen({'a': 'A', 'b': 'B'})",
@@ -231,11 +231,11 @@ def test_hidden_key_dict():
231231

232232

233233
def test_either_dict_or_kwargs():
234-
result = either_dict_or_kwargs(dict(a=1), None, "foo")
234+
result = either_dict_or_kwargs(dict(a=1), {}, "foo")
235235
expected = dict(a=1)
236236
assert result == expected
237237

238-
result = either_dict_or_kwargs(None, dict(a=1), "foo")
238+
result = either_dict_or_kwargs({}, dict(a=1), "foo")
239239
expected = dict(a=1)
240240
assert result == expected
241241

0 commit comments

Comments
 (0)