Skip to content

Commit ee7573b

Browse files
committed
simpler bounds loop
1 parent e5d7882 commit ee7573b

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
@@ -1956,7 +1956,7 @@ def serialize(x, axis):
19561956
return "|".join(x.flatten())
19571957
# np.apply_along_axis does not work with str.join, so we
19581958
# need to loop through the array directly. First move (possibly
1959-
# multiple) axis of interest to trailing dims, then make a 2D
1959+
# multiple) axis of interest to trailing dim(s), then make a 2D
19601960
# array we can loop through.
19611961
work_array = np.moveaxis(x, axis, range(-len(axis), 0))
19621962
out_shape = work_array.shape[: -len(axis)]
@@ -1970,13 +1970,11 @@ def serialize(x, axis):
19701970

19711971
bounds = None
19721972
if self.has_bounds():
1973-
shape = self._bounds_dm.shape[-1:]
19741973
bounds = []
1975-
for index in np.ndindex(shape):
1976-
index_slice = (slice(None),) * self.ndim + tuple(index)
1977-
bounds.append(
1978-
serialize(self.bounds[index_slice], dims_to_collapse)
1979-
)
1974+
for index in range(self.nbounds):
1975+
bounds_slice = np.take(self.bounds, index, axis=-1)
1976+
serialized = serialize(bounds_slice, dims_to_collapse)
1977+
bounds.append(serialized)
19801978
# Make sure bounds dim comes last.
19811979
bounds = np.moveaxis(bounds, 0, -1)
19821980
points = serialize(self.points, dims_to_collapse)

0 commit comments

Comments
 (0)