Skip to content

Commit 4b92b2f

Browse files
committed
simpler bounds loop
1 parent 7e9ef75 commit 4b92b2f

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

lib/iris/coords.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1953,7 +1953,7 @@ def serialize(x, axis):
19531953
return "|".join(x.flatten())
19541954
# np.apply_along_axis does not work with str.join, so we
19551955
# need to loop through the array directly. First move (possibly
1956-
# multiple) axis of interest to trailing dims, then make a 2D
1956+
# multiple) axis of interest to trailing dim(s), then make a 2D
19571957
# array we can loop through.
19581958
work_array = np.moveaxis(x, axis, range(-len(axis), 0))
19591959
out_shape = work_array.shape[: -len(axis)]
@@ -1967,13 +1967,11 @@ def serialize(x, axis):
19671967

19681968
bounds = None
19691969
if self.has_bounds():
1970-
shape = self._bounds_dm.shape[-1:]
19711970
bounds = []
1972-
for index in np.ndindex(shape):
1973-
index_slice = (slice(None),) * self.ndim + tuple(index)
1974-
bounds.append(
1975-
serialize(self.bounds[index_slice], dims_to_collapse)
1976-
)
1971+
for index in range(self.nbounds):
1972+
bounds_slice = np.take(self.bounds, index, axis=-1)
1973+
serialized = serialize(bounds_slice, dims_to_collapse)
1974+
bounds.append(serialized)
19771975
# Make sure bounds dim comes last.
19781976
bounds = np.moveaxis(bounds, 0, -1)
19791977
points = serialize(self.points, dims_to_collapse)

0 commit comments

Comments
 (0)