11
11
from functools import lru_cache
12
12
from itertools import zip_longest
13
13
import operator
14
- from typing import Sequence , Union
14
+ from typing import Iterable , Optional , Union
15
15
import warnings
16
16
import zlib
17
17
34
34
import iris .exceptions
35
35
import iris .time
36
36
import iris .util
37
- import iris .warnings
38
37
39
38
#: The default value for ignore_axis which controls guess_coord_axis' behaviour
40
39
DEFAULT_IGNORE_AXIS = False
41
40
41
+ # Define some typing aliases.
42
+ Dims = Union [int , Iterable [int ]]
43
+ RealData = Union [np .ndarray , ma .MaskedArray ]
44
+ RealOrLazyData = Union [RealData , da .Array ]
45
+
42
46
43
47
class _DimensionalMetadata (CFVariableMixin , metaclass = ABCMeta ):
44
48
"""Superclass for dimensional metadata."""
@@ -240,24 +244,8 @@ def _lazy_values(self):
240
244
"""Return a lazy array representing the dimensional metadata values."""
241
245
return self ._values_dm .lazy_data ()
242
246
243
- < << << << HEAD
244
- def _core_values (self ):
247
+ def _core_values (self ) -> RealOrLazyData :
245
248
"""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
261
249
result = self ._values_dm .core_data ()
262
250
if not _lazy .is_lazy_data (result ):
263
251
result = result .view ()
@@ -789,24 +777,8 @@ def dtype(self):
789
777
return self ._values_dm .dtype
790
778
791
779
@property
792
- < << << << HEAD
793
- def ndim (self ):
794
- """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
780
def ndim (self ) -> int :
804
- """
805
- Return the number of dimensions of the current dimensional metadata
806
- object.
807
-
808
- """
809
- >> >> >> > add type hints
781
+ """Return the number of dimensions of the current dimensional metadata object."""
810
782
return self ._values_dm .ndim
811
783
812
784
def has_bounds (self ):
@@ -1618,17 +1590,9 @@ def points(self, points):
1618
1590
self ._values = points
1619
1591
1620
1592
@property
1621
- < << << << HEAD
1622
- def bounds (self ):
1593
+ def bounds (self ) -> RealData :
1623
1594
"""Coordinate bounds values.
1624
1595
1625
- ||||||| constructed merge base
1626
- def bounds(self):
1627
- """
1628
- == == == =
1629
- def bounds (self ) -> npt .NDArray :
1630
- """
1631
- >>>>>>> add type hints
1632
1596
The coordinate bounds values, as a NumPy array,
1633
1597
or None if no bound values are defined.
1634
1598
@@ -1758,28 +1722,12 @@ def lazy_bounds(self):
1758
1722
lazy_bounds = self ._bounds_dm .lazy_data ()
1759
1723
return lazy_bounds
1760
1724
1761
- def core_points (self ):
1725
+ def core_points (self ) -> RealOrLazyData :
1762
1726
"""Core points array at the core of this coord, which may be a NumPy array or a dask array."""
1763
1727
return super ()._core_values ()
1764
1728
1765
- << << << < HEAD
1766
- def core_bounds (self ):
1729
+ def core_bounds (self ) -> RealOrLazyData :
1767
1730
"""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
1783
1731
result = None
1784
1732
if self .has_bounds ():
1785
1733
result = self ._bounds_dm .core_data ()
@@ -2157,9 +2105,7 @@ def cell(self, index):
2157
2105
2158
2106
return Cell (point , bound )
2159
2107
2160
- def collapsed (
2161
- self , dims_to_collapse : Union [int , Sequence [int ], None ] = None
2162
- ) -> "Coord" :
2108
+ def collapsed (self , dims_to_collapse : Optional [Dims ] = None ) -> "Coord" :
2163
2109
"""
2164
2110
Returns a copy of this coordinate, which has been collapsed along the specified dimensions.
2165
2111
@@ -2176,8 +2122,8 @@ def collapsed(
2176
2122
# Collapse the coordinate by serializing the points and
2177
2123
# bounds as strings.
2178
2124
def serialize (
2179
- x : npt .NDArray , axis : Union [ Sequence [int ], None ]
2180
- ) -> Union [npt .NDArray , str ]:
2125
+ x : npt .NDArray [ np . str_ ] , axis : Optional [ Iterable [int ]]
2126
+ ) -> Union [npt .NDArray [ np . str_ ] , str ]:
2181
2127
if axis is None :
2182
2128
return "|" .join (str (i ) for i in x .flatten ())
2183
2129
0 commit comments