Skip to content

Commit

Permalink
add type hints
Browse files Browse the repository at this point in the history
  • Loading branch information
rcomer committed Dec 30, 2021
1 parent 63b372c commit f966938
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions lib/iris/coords.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@
import copy
from itertools import chain, zip_longest
import operator
from typing import Sequence, Union
import warnings
import zlib

import cftime
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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand All @@ -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())

Expand Down

0 comments on commit f966938

Please sign in to comment.