Skip to content

Commit d51ed98

Browse files
committed
slicing loops -= 1
1 parent 2e889cf commit d51ed98

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

lib/iris/coords.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2252,13 +2252,15 @@ def serialize(x, axis):
22522252

22532253
bounds = None
22542254
if self.has_bounds():
2255-
bounds = []
2256-
for index in range(self.nbounds):
2257-
bounds_slice = np.take(self.bounds, index, axis=-1)
2258-
serialized = serialize(bounds_slice, dims_to_collapse)
2259-
bounds.append(serialized)
2260-
# Make sure bounds dim comes last.
2261-
bounds = np.moveaxis(bounds, 0, -1)
2255+
# Express dims_to_collapse as non-negative integers.
2256+
if dims_to_collapse is None:
2257+
dims_to_collapse = range(self.ndim)
2258+
else:
2259+
dims_to_collapse = tuple(
2260+
dim % self.ndim for dim in dims_to_collapse
2261+
)
2262+
bounds = serialize(self.bounds, dims_to_collapse)
2263+
22622264
points = serialize(self.points, dims_to_collapse)
22632265
# Create the new collapsed coordinate.
22642266
coord = self.copy(points=np.array(points), bounds=bounds)

0 commit comments

Comments
 (0)