Skip to content

Commit 484a02b

Browse files
committed
remove dubious check; reorder tests
1 parent 92b174f commit 484a02b

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

lib/iris/coords.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -1949,7 +1949,7 @@ def collapsed(self, dims_to_collapse=None):
19491949
# Collapse the coordinate by serializing the points and
19501950
# bounds as strings.
19511951
def serialize(x, axis):
1952-
if axis is None or len(axis) == x.ndim:
1952+
if axis is None:
19531953
return "|".join(str(i) for i in x.flatten())
19541954

19551955
# np.apply_along_axis does not work with str.join, so we
@@ -1958,7 +1958,9 @@ def serialize(x, axis):
19581958
# array we can loop through.
19591959
work_array = np.moveaxis(x, axis, range(-len(axis), 0))
19601960
out_shape = work_array.shape[: -len(axis)]
1961-
work_array = work_array.reshape(np.prod(out_shape), -1)
1961+
work_array = work_array.reshape(
1962+
np.prod(out_shape, dtype=int), -1
1963+
)
19621964

19631965
joined = []
19641966
for arr_slice in work_array:

lib/iris/tests/unit/coords/test_Coord.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,15 @@ def test_lazy_nd_points_and_bounds(self):
470470
self.assertArrayEqual(collapsed_coord.points, da.array([55]))
471471
self.assertArrayEqual(collapsed_coord.bounds, da.array([[-2, 112]]))
472472

473+
def test_string_masked(self):
474+
points = ma.array(["foo", "bar", "bing"], mask=[0, 1, 0], dtype=str)
475+
coord = AuxCoord(points)
476+
477+
collapsed_coord = coord.collapsed(0)
478+
479+
expected = "foo|--|bing"
480+
self.assertEqual(collapsed_coord.points, expected)
481+
473482
def test_string_nd_first(self):
474483
self.setupTestArrays((3, 4))
475484
coord = AuxCoord(self.pts_real.astype(str))
@@ -484,15 +493,6 @@ def test_string_nd_first(self):
484493

485494
self.assertArrayEqual(collapsed_coord.points, expected)
486495

487-
def test_string_masked(self):
488-
points = ma.array(["foo", "bar", "bing"], mask=[0, 1, 0], dtype=str)
489-
coord = AuxCoord(points)
490-
491-
collapsed_coord = coord.collapsed(0)
492-
493-
expected = "foo|--|bing"
494-
self.assertEqual(collapsed_coord.points, expected)
495-
496496
def test_string_nd_second(self):
497497
self.setupTestArrays((3, 4))
498498
coord = AuxCoord(self.pts_real.astype(str))

0 commit comments

Comments
 (0)