1414import copy
1515from itertools import chain , zip_longest
1616import operator
17- from typing import Sequence , Union
17+ from typing import Iterable , Optional , Union
1818import warnings
1919import zlib
2020
3939import iris .time
4040import iris .util
4141
42+ # Define some typing aliases.
43+ Dims = Union [int , Iterable [int ]]
44+ RealData = Union [np .ndarray , ma .MaskedArray ]
45+ RealOrLazyData = Union [RealData , da .Array ]
46+
4247
4348class _DimensionalMetadata (CFVariableMixin , metaclass = ABCMeta ):
4449 """
@@ -250,7 +255,7 @@ def _lazy_values(self):
250255 """
251256 return self ._values_dm .lazy_data ()
252257
253- def _core_values (self ) -> Union [ npt . NDArray , "da.Array" ] :
258+ def _core_values (self ) -> RealOrLazyData :
254259 """
255260 The values array of this dimensional metadata which may be a NumPy
256261 array or a dask array.
@@ -1447,7 +1452,7 @@ def points(self, points):
14471452 self ._values = points
14481453
14491454 @property
1450- def bounds (self ) -> npt . NDArray :
1455+ def bounds (self ) -> RealData :
14511456 """
14521457 The coordinate bounds values, as a NumPy array,
14531458 or None if no bound values are defined.
@@ -1565,15 +1570,15 @@ def lazy_bounds(self):
15651570 lazy_bounds = self ._bounds_dm .lazy_data ()
15661571 return lazy_bounds
15671572
1568- def core_points (self ):
1573+ def core_points (self ) -> RealOrLazyData :
15691574 """
15701575 The points array at the core of this coord, which may be a NumPy array
15711576 or a dask array.
15721577
15731578 """
15741579 return super ()._core_values ()
15751580
1576- def core_bounds (self ) -> Union [ npt . NDArray , "da.Array" ] :
1581+ def core_bounds (self ) -> RealOrLazyData :
15771582 """
15781583 The points array at the core of this coord, which may be a NumPy array
15791584 or a dask array.
@@ -1935,9 +1940,7 @@ def cell(self, index):
19351940
19361941 return Cell (point , bound )
19371942
1938- def collapsed (
1939- self , dims_to_collapse : Union [int , Sequence [int ], None ] = None
1940- ) -> "Coord" :
1943+ def collapsed (self , dims_to_collapse : Optional [Dims ] = None ) -> "Coord" :
19411944 """
19421945 Returns a copy of this coordinate, which has been collapsed along
19431946 the specified dimensions.
@@ -1956,8 +1959,8 @@ def collapsed(
19561959 # Collapse the coordinate by serializing the points and
19571960 # bounds as strings.
19581961 def serialize (
1959- x : npt .NDArray , axis : Union [ Sequence [int ], None ]
1960- ) -> Union [npt .NDArray , str ]:
1962+ x : npt .NDArray [ np . str_ ] , axis : Optional [ Iterable [int ]]
1963+ ) -> Union [npt .NDArray [ np . str_ ] , str ]:
19611964 if axis is None :
19621965 return "|" .join (str (i ) for i in x .flatten ())
19631966
0 commit comments