14
14
import copy
15
15
from itertools import chain , zip_longest
16
16
import operator
17
- from typing import Sequence , Union
17
+ from typing import Iterable , Optional , Union
18
18
import warnings
19
19
import zlib
20
20
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
"""
@@ -250,7 +255,7 @@ def _lazy_values(self):
250
255
"""
251
256
return self ._values_dm .lazy_data ()
252
257
253
- def _core_values (self ) -> Union [ npt . NDArray , "da.Array" ] :
258
+ def _core_values (self ) -> RealOrLazyData :
254
259
"""
255
260
The values array of this dimensional metadata which may be a NumPy
256
261
array or a dask array.
@@ -1447,7 +1452,7 @@ def points(self, points):
1447
1452
self ._values = points
1448
1453
1449
1454
@property
1450
- def bounds (self ) -> npt . NDArray :
1455
+ def bounds (self ) -> RealData :
1451
1456
"""
1452
1457
The coordinate bounds values, as a NumPy array,
1453
1458
or None if no bound values are defined.
@@ -1565,15 +1570,15 @@ def lazy_bounds(self):
1565
1570
lazy_bounds = self ._bounds_dm .lazy_data ()
1566
1571
return lazy_bounds
1567
1572
1568
- def core_points (self ):
1573
+ def core_points (self ) -> RealOrLazyData :
1569
1574
"""
1570
1575
The points array at the core of this coord, which may be a NumPy array
1571
1576
or a dask array.
1572
1577
1573
1578
"""
1574
1579
return super ()._core_values ()
1575
1580
1576
- def core_bounds (self ) -> Union [ npt . NDArray , "da.Array" ] :
1581
+ def core_bounds (self ) -> RealOrLazyData :
1577
1582
"""
1578
1583
The points array at the core of this coord, which may be a NumPy array
1579
1584
or a dask array.
@@ -1935,9 +1940,7 @@ def cell(self, index):
1935
1940
1936
1941
return Cell (point , bound )
1937
1942
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" :
1941
1944
"""
1942
1945
Returns a copy of this coordinate, which has been collapsed along
1943
1946
the specified dimensions.
@@ -1956,8 +1959,8 @@ def collapsed(
1956
1959
# Collapse the coordinate by serializing the points and
1957
1960
# bounds as strings.
1958
1961
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 ]:
1961
1964
if axis is None :
1962
1965
return "|" .join (str (i ) for i in x .flatten ())
1963
1966
0 commit comments