Skip to content

Commit 882b5be

Browse files
committed
add type hints
1 parent eaed684 commit 882b5be

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

lib/iris/coords.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@
1414
from functools import lru_cache
1515
from itertools import zip_longest
1616
import operator
17+
from typing import Sequence, Union
1718
import warnings
1819
import zlib
1920

2021
import dask.array as da
2122
import numpy as np
2223
import numpy.ma as ma
24+
import numpy.typing as npt
2325

2426
from iris._data_manager import DataManager
2527
import iris._lazy_data as _lazy
@@ -254,7 +256,7 @@ def _lazy_values(self):
254256
"""
255257
return self._values_dm.lazy_data()
256258

257-
def _core_values(self):
259+
def _core_values(self) -> Union[npt.NDArray, "da.Array"]:
258260
"""
259261
The values array of this dimensional metadata which may be a NumPy
260262
array or a dask array.
@@ -805,7 +807,7 @@ def dtype(self):
805807
return self._values_dm.dtype
806808

807809
@property
808-
def ndim(self):
810+
def ndim(self) -> int:
809811
"""
810812
Return the number of dimensions of the current dimensional metadata
811813
object.
@@ -1671,7 +1673,7 @@ def points(self, points):
16711673
self._values = points
16721674

16731675
@property
1674-
def bounds(self):
1676+
def bounds(self) -> npt.NDArray:
16751677
"""
16761678
The coordinate bounds values, as a NumPy array,
16771679
or None if no bound values are defined.
@@ -1815,7 +1817,7 @@ def core_points(self):
18151817
"""
18161818
return super()._core_values()
18171819

1818-
def core_bounds(self):
1820+
def core_bounds(self) -> Union[npt.NDArray, "da.Array"]:
18191821
"""
18201822
The points array at the core of this coord, which may be a NumPy array
18211823
or a dask array.
@@ -2214,7 +2216,9 @@ def cell(self, index):
22142216

22152217
return Cell(point, bound)
22162218

2217-
def collapsed(self, dims_to_collapse=None):
2219+
def collapsed(
2220+
self, dims_to_collapse: Union[int, Sequence[int], None] = None
2221+
) -> "Coord":
22182222
"""
22192223
Returns a copy of this coordinate, which has been collapsed along
22202224
the specified dimensions.
@@ -2232,7 +2236,9 @@ def collapsed(self, dims_to_collapse=None):
22322236
if np.issubdtype(self.dtype, np.str_):
22332237
# Collapse the coordinate by serializing the points and
22342238
# bounds as strings.
2235-
def serialize(x, axis):
2239+
def serialize(
2240+
x: npt.NDArray, axis: Union[Sequence[int], None]
2241+
) -> Union[npt.NDArray, str]:
22362242
if axis is None:
22372243
return "|".join(str(i) for i in x.flatten())
22382244

0 commit comments

Comments
 (0)