Skip to content

Commit 9e9e348

Browse files
committed
remove dubious check; reorder tests
1 parent e236779 commit 9e9e348

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

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

21302132
joined = []
21312133
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
@@ -702,6 +702,15 @@ def test_lazy_3_bounds(self):
702702
self.assertArrayAlmostEqual(collapsed_coord.points, da.array([2.0]))
703703
self.assertArrayAlmostEqual(collapsed_coord.bounds, da.array([[0.0, 4.0]]))
704704

705+
def test_string_masked(self):
706+
points = ma.array(["foo", "bar", "bing"], mask=[0, 1, 0], dtype=str)
707+
coord = AuxCoord(points)
708+
709+
collapsed_coord = coord.collapsed(0)
710+
711+
expected = "foo|--|bing"
712+
self.assertEqual(collapsed_coord.points, expected)
713+
705714
def test_string_nd_first(self):
706715
self.setupTestArrays((3, 4))
707716
coord = AuxCoord(self.pts_real.astype(str))
@@ -716,15 +725,6 @@ def test_string_nd_first(self):
716725

717726
self.assertArrayEqual(collapsed_coord.points, expected)
718727

719-
def test_string_masked(self):
720-
points = ma.array(["foo", "bar", "bing"], mask=[0, 1, 0], dtype=str)
721-
coord = AuxCoord(points)
722-
723-
collapsed_coord = coord.collapsed(0)
724-
725-
expected = "foo|--|bing"
726-
self.assertEqual(collapsed_coord.points, expected)
727-
728728
def test_string_nd_second(self):
729729
self.setupTestArrays((3, 4))
730730
coord = AuxCoord(self.pts_real.astype(str))

0 commit comments

Comments
 (0)