Skip to content

Commit 2aadc98

Browse files
committed
slicing loops -= 1
1 parent 1efe839 commit 2aadc98

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

lib/iris/coords.py

+9-7
Original file line numberDiff line numberDiff line change
@@ -1971,13 +1971,15 @@ def serialize(x, axis):
19711971

19721972
bounds = None
19731973
if self.has_bounds():
1974-
bounds = []
1975-
for index in range(self.nbounds):
1976-
bounds_slice = np.take(self.bounds, index, axis=-1)
1977-
serialized = serialize(bounds_slice, dims_to_collapse)
1978-
bounds.append(serialized)
1979-
# Make sure bounds dim comes last.
1980-
bounds = np.moveaxis(bounds, 0, -1)
1974+
# Express dims_to_collapse as non-negative integers.
1975+
if dims_to_collapse is None:
1976+
dims_to_collapse = range(self.ndim)
1977+
else:
1978+
dims_to_collapse = tuple(
1979+
dim % self.ndim for dim in dims_to_collapse
1980+
)
1981+
bounds = serialize(self.bounds, dims_to_collapse)
1982+
19811983
points = serialize(self.points, dims_to_collapse)
19821984
# Create the new collapsed coordinate.
19831985
coord = self.copy(points=np.array(points), bounds=bounds)

0 commit comments

Comments
 (0)