Skip to content

Commit 99c359d

Browse files
committed
slicing loops -= 1
1 parent 1b2347a commit 99c359d

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
@@ -1968,13 +1968,15 @@ def serialize(x, axis):
19681968

19691969
bounds = None
19701970
if self.has_bounds():
1971-
bounds = []
1972-
for index in range(self.nbounds):
1973-
bounds_slice = np.take(self.bounds, index, axis=-1)
1974-
serialized = serialize(bounds_slice, dims_to_collapse)
1975-
bounds.append(serialized)
1976-
# Make sure bounds dim comes last.
1977-
bounds = np.moveaxis(bounds, 0, -1)
1971+
# Express dims_to_collapse as non-negative integers.
1972+
if dims_to_collapse is None:
1973+
dims_to_collapse = range(self.ndim)
1974+
else:
1975+
dims_to_collapse = tuple(
1976+
dim % self.ndim for dim in dims_to_collapse
1977+
)
1978+
bounds = serialize(self.bounds, dims_to_collapse)
1979+
19781980
points = serialize(self.points, dims_to_collapse)
19791981
# Create the new collapsed coordinate.
19801982
coord = self.copy(points=np.array(points), bounds=bounds)

0 commit comments

Comments
 (0)