Skip to content

Commit 0b97969

Browse files
authored
Test type annotations for Variable.get_axis_num (#9832)
This is a regression test for GH9822.
1 parent f3a65d5 commit 0b97969

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

xarray/tests/test_variable.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1604,14 +1604,19 @@ def test_squeeze(self):
16041604
with pytest.raises(ValueError, match=r"cannot select a dimension"):
16051605
v.squeeze("y")
16061606

1607-
def test_get_axis_num(self):
1607+
def test_get_axis_num(self) -> None:
16081608
v = Variable(["x", "y", "z"], np.random.randn(2, 3, 4))
16091609
assert v.get_axis_num("x") == 0
16101610
assert v.get_axis_num(["x"]) == (0,)
16111611
assert v.get_axis_num(["x", "y"]) == (0, 1)
16121612
assert v.get_axis_num(["z", "y", "x"]) == (2, 1, 0)
16131613
with pytest.raises(ValueError, match=r"not found in array dim"):
16141614
v.get_axis_num("foobar")
1615+
# Test the type annotations: mypy will complain if the inferred
1616+
# type is wrong
1617+
v.get_axis_num("x") + 0
1618+
v.get_axis_num(["x"]) + ()
1619+
v.get_axis_num(("x", "y")) + ()
16151620

16161621
def test_set_dims(self):
16171622
v = Variable(["x"], [0, 1])

0 commit comments

Comments
 (0)