Skip to content

Commit 13a5a12

Browse files
committed
add type hints
1 parent 8b6c5fa commit 13a5a12

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

lib/iris/coords.py

+12-6
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@
1414
import copy
1515
from itertools import chain, zip_longest
1616
import operator
17+
from typing import Sequence, Union
1718
import warnings
1819
import zlib
1920

2021
import cftime
2122
import dask.array as da
2223
import numpy as np
2324
import numpy.ma as ma
25+
import numpy.typing as npt
2426

2527
from iris._data_manager import DataManager
2628
import iris._lazy_data as _lazy
@@ -248,7 +250,7 @@ def _lazy_values(self):
248250
"""
249251
return self._values_dm.lazy_data()
250252

251-
def _core_values(self):
253+
def _core_values(self) -> Union[npt.NDArray, "da.Array"]:
252254
"""
253255
The values array of this dimensional metadata which may be a NumPy
254256
array or a dask array.
@@ -545,7 +547,7 @@ def dtype(self):
545547
return self._values_dm.dtype
546548

547549
@property
548-
def ndim(self):
550+
def ndim(self) -> int:
549551
"""
550552
Return the number of dimensions of the current dimensional metadata
551553
object.
@@ -1445,7 +1447,7 @@ def points(self, points):
14451447
self._values = points
14461448

14471449
@property
1448-
def bounds(self):
1450+
def bounds(self) -> npt.NDArray:
14491451
"""
14501452
The coordinate bounds values, as a NumPy array,
14511453
or None if no bound values are defined.
@@ -1571,7 +1573,7 @@ def core_points(self):
15711573
"""
15721574
return super()._core_values()
15731575

1574-
def core_bounds(self):
1576+
def core_bounds(self) -> Union[npt.NDArray, "da.Array"]:
15751577
"""
15761578
The points array at the core of this coord, which may be a NumPy array
15771579
or a dask array.
@@ -1933,7 +1935,9 @@ def cell(self, index):
19331935

19341936
return Cell(point, bound)
19351937

1936-
def collapsed(self, dims_to_collapse=None):
1938+
def collapsed(
1939+
self, dims_to_collapse: Union[int, Sequence[int], None] = None
1940+
) -> "Coord":
19371941
"""
19381942
Returns a copy of this coordinate, which has been collapsed along
19391943
the specified dimensions.
@@ -1951,7 +1955,9 @@ def collapsed(self, dims_to_collapse=None):
19511955
if np.issubdtype(self.dtype, np.str_):
19521956
# Collapse the coordinate by serializing the points and
19531957
# bounds as strings.
1954-
def serialize(x, axis):
1958+
def serialize(
1959+
x: npt.NDArray, axis: Union[Sequence[int], None]
1960+
) -> Union[npt.NDArray, str]:
19551961
if axis is None:
19561962
return "|".join(str(i) for i in x.flatten())
19571963

0 commit comments

Comments
 (0)