diff --git a/lib/iris/coords.py b/lib/iris/coords.py index 6127c98040..ffd3df5504 100644 --- a/lib/iris/coords.py +++ b/lib/iris/coords.py @@ -14,6 +14,7 @@ import copy from itertools import chain, zip_longest import operator +from typing import Sequence, Union import warnings import zlib @@ -21,6 +22,7 @@ import dask.array as da import numpy as np import numpy.ma as ma +import numpy.typing as npt from iris._data_manager import DataManager import iris._lazy_data as _lazy @@ -248,7 +250,7 @@ def _lazy_values(self): """ return self._values_dm.lazy_data() - def _core_values(self): + def _core_values(self) -> Union[npt.NDArray, "da.Array"]: """ The values array of this dimensional metadata which may be a NumPy array or a dask array. @@ -545,7 +547,7 @@ def dtype(self): return self._values_dm.dtype @property - def ndim(self): + def ndim(self) -> int: """ Return the number of dimensions of the current dimensional metadata object. @@ -1445,7 +1447,7 @@ def points(self, points): self._values = points @property - def bounds(self): + def bounds(self) -> npt.NDArray: """ The coordinate bounds values, as a NumPy array, or None if no bound values are defined. @@ -1571,7 +1573,7 @@ def core_points(self): """ return super()._core_values() - def core_bounds(self): + def core_bounds(self) -> Union[npt.NDArray, "da.Array"]: """ The points array at the core of this coord, which may be a NumPy array or a dask array. @@ -1933,7 +1935,9 @@ def cell(self, index): return Cell(point, bound) - def collapsed(self, dims_to_collapse=None): + def collapsed( + self, dims_to_collapse: Union[int, Sequence[int], None] = None + ) -> "Coord": """ Returns a copy of this coordinate, which has been collapsed along the specified dimensions. @@ -1951,7 +1955,9 @@ def collapsed(self, dims_to_collapse=None): if np.issubdtype(self.dtype, np.str_): # Collapse the coordinate by serializing the points and # bounds as strings. - def serialize(x, axis): + def serialize( + x: npt.NDArray, axis: Union[Sequence[int], None] + ) -> Union[npt.NDArray, str]: if axis is None: return "|".join(str(i) for i in x.flatten())