15
15
from functools import lru_cache
16
16
from itertools import zip_longest
17
17
import operator
18
- from typing import Sequence , Union
18
+ from typing import Iterable , Optional , Union
19
19
import warnings
20
20
import zlib
21
21
39
39
import iris .time
40
40
import iris .util
41
41
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
+
42
47
43
48
class _DimensionalMetadata (CFVariableMixin , metaclass = ABCMeta ):
44
49
"""
@@ -254,7 +259,7 @@ def _lazy_values(self):
254
259
"""
255
260
return self ._values_dm .lazy_data ()
256
261
257
- def _core_values (self ) -> Union [ npt . NDArray , "da.Array" ] :
262
+ def _core_values (self ) -> RealOrLazyData :
258
263
"""
259
264
The values array of this dimensional metadata which may be a NumPy
260
265
array or a dask array.
@@ -1659,7 +1664,7 @@ def points(self, points):
1659
1664
self ._values = points
1660
1665
1661
1666
@property
1662
- def bounds (self ) -> npt . NDArray :
1667
+ def bounds (self ) -> RealData :
1663
1668
"""
1664
1669
The coordinate bounds values, as a NumPy array,
1665
1670
or None if no bound values are defined.
@@ -1777,15 +1782,15 @@ def lazy_bounds(self):
1777
1782
lazy_bounds = self ._bounds_dm .lazy_data ()
1778
1783
return lazy_bounds
1779
1784
1780
- def core_points (self ):
1785
+ def core_points (self ) -> RealOrLazyData :
1781
1786
"""
1782
1787
The points array at the core of this coord, which may be a NumPy array
1783
1788
or a dask array.
1784
1789
1785
1790
"""
1786
1791
return super ()._core_values ()
1787
1792
1788
- def core_bounds (self ) -> Union [ npt . NDArray , "da.Array" ] :
1793
+ def core_bounds (self ) -> RealOrLazyData :
1789
1794
"""
1790
1795
The points array at the core of this coord, which may be a NumPy array
1791
1796
or a dask array.
@@ -2184,9 +2189,7 @@ def cell(self, index):
2184
2189
2185
2190
return Cell (point , bound )
2186
2191
2187
- def collapsed (
2188
- self , dims_to_collapse : Union [int , Sequence [int ], None ] = None
2189
- ) -> "Coord" :
2192
+ def collapsed (self , dims_to_collapse : Optional [Dims ] = None ) -> "Coord" :
2190
2193
"""
2191
2194
Returns a copy of this coordinate, which has been collapsed along
2192
2195
the specified dimensions.
@@ -2205,8 +2208,8 @@ def collapsed(
2205
2208
# Collapse the coordinate by serializing the points and
2206
2209
# bounds as strings.
2207
2210
def serialize (
2208
- x : npt .NDArray , axis : Union [ Sequence [int ], None ]
2209
- ) -> Union [npt .NDArray , str ]:
2211
+ x : npt .NDArray [ np . str_ ] , axis : Optional [ Iterable [int ]]
2212
+ ) -> Union [npt .NDArray [ np . str_ ] , str ]:
2210
2213
if axis is None :
2211
2214
return "|" .join (str (i ) for i in x .flatten ())
2212
2215
0 commit comments