Skip to content

Commit 07a3e77

Browse files
committed
add type hints
1 parent e625519 commit 07a3e77

File tree

1 file changed

+66
-3
lines changed

1 file changed

+66
-3
lines changed

lib/iris/coords.py

Lines changed: 66 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@
1111
from functools import lru_cache
1212
from itertools import zip_longest
1313
import operator
14+
from typing import Sequence, Union
1415
import warnings
1516
import zlib
1617

1718
import dask.array as da
1819
import numpy as np
1920
import numpy.ma as ma
21+
import numpy.typing as npt
2022

2123
from iris._data_manager import DataManager
2224
import iris._lazy_data as _lazy
@@ -238,8 +240,24 @@ def _lazy_values(self):
238240
"""Return a lazy array representing the dimensional metadata values."""
239241
return self._values_dm.lazy_data()
240242

243+
<<<<<<< HEAD
241244
def _core_values(self):
242245
"""Value array of this dimensional metadata which may be a NumPy array or a dask array."""
246+
||||||| constructed merge base
247+
def _core_values(self):
248+
"""
249+
The values array of this dimensional metadata which may be a NumPy
250+
array or a dask array.
251+
252+
"""
253+
=======
254+
def _core_values(self) -> Union[npt.NDArray, "da.Array"]:
255+
"""
256+
The values array of this dimensional metadata which may be a NumPy
257+
array or a dask array.
258+
259+
"""
260+
>>>>>>> add type hints
243261
result = self._values_dm.core_data()
244262
if not _lazy.is_lazy_data(result):
245263
result = result.view()
@@ -771,8 +789,24 @@ def dtype(self):
771789
return self._values_dm.dtype
772790

773791
@property
792+
<<<<<<< HEAD
774793
def ndim(self):
775794
"""Return the number of dimensions of the current dimensional metadata object."""
795+
||||||| constructed merge base
796+
def ndim(self):
797+
"""
798+
Return the number of dimensions of the current dimensional metadata
799+
object.
800+
801+
"""
802+
=======
803+
def ndim(self) -> int:
804+
"""
805+
Return the number of dimensions of the current dimensional metadata
806+
object.
807+
808+
"""
809+
>>>>>>> add type hints
776810
return self._values_dm.ndim
777811

778812
def has_bounds(self):
@@ -1584,9 +1618,17 @@ def points(self, points):
15841618
self._values = points
15851619

15861620
@property
1621+
<<<<<<< HEAD
15871622
def bounds(self):
15881623
"""Coordinate bounds values.
15891624
1625+
||||||| constructed merge base
1626+
def bounds(self):
1627+
"""
1628+
=======
1629+
def bounds(self) -> npt.NDArray:
1630+
"""
1631+
>>>>>>> add type hints
15901632
The coordinate bounds values, as a NumPy array,
15911633
or None if no bound values are defined.
15921634
@@ -1720,8 +1762,24 @@ def core_points(self):
17201762
"""Core points array at the core of this coord, which may be a NumPy array or a dask array."""
17211763
return super()._core_values()
17221764

1765+
<<<<<<< HEAD
17231766
def core_bounds(self):
17241767
"""Core bounds. The points array at the core of this coord, which may be a NumPy array or a dask array."""
1768+
||||||| constructed merge base
1769+
def core_bounds(self):
1770+
"""
1771+
The points array at the core of this coord, which may be a NumPy array
1772+
or a dask array.
1773+
1774+
"""
1775+
=======
1776+
def core_bounds(self) -> Union[npt.NDArray, "da.Array"]:
1777+
"""
1778+
The points array at the core of this coord, which may be a NumPy array
1779+
or a dask array.
1780+
1781+
"""
1782+
>>>>>>> add type hints
17251783
result = None
17261784
if self.has_bounds():
17271785
result = self._bounds_dm.core_data()
@@ -2099,8 +2157,11 @@ def cell(self, index):
20992157

21002158
return Cell(point, bound)
21012159

2102-
def collapsed(self, dims_to_collapse=None):
2103-
"""Return a copy of this coordinate, which has been collapsed along the specified dimensions.
2160+
def collapsed(
2161+
self, dims_to_collapse: Union[int, Sequence[int], None] = None
2162+
) -> "Coord":
2163+
"""
2164+
Returns a copy of this coordinate, which has been collapsed along the specified dimensions.
21042165
21052166
Replaces the points & bounds with a simple bounded region.
21062167
"""
@@ -2114,7 +2175,9 @@ def collapsed(self, dims_to_collapse=None):
21142175
if np.issubdtype(self.dtype, np.str_):
21152176
# Collapse the coordinate by serializing the points and
21162177
# bounds as strings.
2117-
def serialize(x, axis):
2178+
def serialize(
2179+
x: npt.NDArray, axis: Union[Sequence[int], None]
2180+
) -> Union[npt.NDArray, str]:
21182181
if axis is None:
21192182
return "|".join(str(i) for i in x.flatten())
21202183

0 commit comments

Comments
 (0)