Skip to content

Commit e625519

Browse files
committed
remove dubious check; reorder tests
1 parent ae1671b commit e625519

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
@@ -2115,7 +2115,7 @@ def collapsed(self, dims_to_collapse=None):
21152115
# Collapse the coordinate by serializing the points and
21162116
# bounds as strings.
21172117
def serialize(x, axis):
2118-
if axis is None or len(axis) == x.ndim:
2118+
if axis is None:
21192119
return "|".join(str(i) for i in x.flatten())
21202120

21212121
# np.apply_along_axis does not work with str.join, so we
@@ -2124,7 +2124,9 @@ def serialize(x, axis):
21242124
# array we can loop through.
21252125
work_array = np.moveaxis(x, axis, range(-len(axis), 0))
21262126
out_shape = work_array.shape[: -len(axis)]
2127-
work_array = work_array.reshape(np.prod(out_shape), -1)
2127+
work_array = work_array.reshape(
2128+
np.prod(out_shape, dtype=int), -1
2129+
)
21282130

21292131
joined = []
21302132
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
@@ -543,6 +543,15 @@ def test_lazy_3_bounds(self):
543543
self.assertArrayAlmostEqual(collapsed_coord.points, da.array([2.0]))
544544
self.assertArrayAlmostEqual(collapsed_coord.bounds, da.array([[0.0, 4.0]]))
545545

546+
def test_string_masked(self):
547+
points = ma.array(["foo", "bar", "bing"], mask=[0, 1, 0], dtype=str)
548+
coord = AuxCoord(points)
549+
550+
collapsed_coord = coord.collapsed(0)
551+
552+
expected = "foo|--|bing"
553+
self.assertEqual(collapsed_coord.points, expected)
554+
546555
def test_string_nd_first(self):
547556
self.setupTestArrays((3, 4))
548557
coord = AuxCoord(self.pts_real.astype(str))
@@ -557,15 +566,6 @@ def test_string_nd_first(self):
557566

558567
self.assertArrayEqual(collapsed_coord.points, expected)
559568

560-
def test_string_masked(self):
561-
points = ma.array(["foo", "bar", "bing"], mask=[0, 1, 0], dtype=str)
562-
coord = AuxCoord(points)
563-
564-
collapsed_coord = coord.collapsed(0)
565-
566-
expected = "foo|--|bing"
567-
self.assertEqual(collapsed_coord.points, expected)
568-
569569
def test_string_nd_second(self):
570570
self.setupTestArrays((3, 4))
571571
coord = AuxCoord(self.pts_real.astype(str))

0 commit comments

Comments
 (0)