Skip to content

Commit 7214fec

Browse files
committed
slicing loops -= 1
1 parent e47693f commit 7214fec

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

22252225
bounds = None
22262226
if self.has_bounds():
2227-
bounds = []
2228-
for index in range(self.nbounds):
2229-
bounds_slice = np.take(self.bounds, index, axis=-1)
2230-
serialized = serialize(bounds_slice, dims_to_collapse)
2231-
bounds.append(serialized)
2232-
# Make sure bounds dim comes last.
2233-
bounds = np.moveaxis(bounds, 0, -1)
2227+
# Express dims_to_collapse as non-negative integers.
2228+
if dims_to_collapse is None:
2229+
dims_to_collapse = range(self.ndim)
2230+
else:
2231+
dims_to_collapse = tuple(
2232+
dim % self.ndim for dim in dims_to_collapse
2233+
)
2234+
bounds = serialize(self.bounds, dims_to_collapse)
2235+
22342236
points = serialize(self.points, dims_to_collapse)
22352237
# Create the new collapsed coordinate.
22362238
coord = self.copy(points=np.array(points), bounds=bounds)

0 commit comments

Comments
 (0)