Skip to content

Commit eaed684

Browse files
committed
remove dubious check; reorder tests
1 parent d51ed98 commit eaed684

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

lib/iris/coords.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2233,7 +2233,7 @@ def collapsed(self, dims_to_collapse=None):
22332233
# Collapse the coordinate by serializing the points and
22342234
# bounds as strings.
22352235
def serialize(x, axis):
2236-
if axis is None or len(axis) == x.ndim:
2236+
if axis is None:
22372237
return "|".join(str(i) for i in x.flatten())
22382238

22392239
# np.apply_along_axis does not work with str.join, so we
@@ -2242,7 +2242,9 @@ def serialize(x, axis):
22422242
# array we can loop through.
22432243
work_array = np.moveaxis(x, axis, range(-len(axis), 0))
22442244
out_shape = work_array.shape[: -len(axis)]
2245-
work_array = work_array.reshape(np.prod(out_shape), -1)
2245+
work_array = work_array.reshape(
2246+
np.prod(out_shape, dtype=int), -1
2247+
)
22462248

22472249
joined = []
22482250
for arr_slice in work_array:

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,15 @@ def test_lazy_3_bounds(self):
565565
collapsed_coord.bounds, da.array([[0.0, 4.0]])
566566
)
567567

568+
def test_string_masked(self):
569+
points = ma.array(["foo", "bar", "bing"], mask=[0, 1, 0], dtype=str)
570+
coord = AuxCoord(points)
571+
572+
collapsed_coord = coord.collapsed(0)
573+
574+
expected = "foo|--|bing"
575+
self.assertEqual(collapsed_coord.points, expected)
576+
568577
def test_string_nd_first(self):
569578
self.setupTestArrays((3, 4))
570579
coord = AuxCoord(self.pts_real.astype(str))
@@ -579,15 +588,6 @@ def test_string_nd_first(self):
579588

580589
self.assertArrayEqual(collapsed_coord.points, expected)
581590

582-
def test_string_masked(self):
583-
points = ma.array(["foo", "bar", "bing"], mask=[0, 1, 0], dtype=str)
584-
coord = AuxCoord(points)
585-
586-
collapsed_coord = coord.collapsed(0)
587-
588-
expected = "foo|--|bing"
589-
self.assertEqual(collapsed_coord.points, expected)
590-
591591
def test_string_nd_second(self):
592592
self.setupTestArrays((3, 4))
593593
coord = AuxCoord(self.pts_real.astype(str))

0 commit comments

Comments
 (0)