Skip to content

Commit

Permalink
remove dubious check; reorder tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rcomer committed Dec 30, 2021
1 parent 1baac74 commit 63b372c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
6 changes: 4 additions & 2 deletions lib/iris/coords.py
Original file line number Diff line number Diff line change
Expand Up @@ -1952,7 +1952,7 @@ def collapsed(self, dims_to_collapse=None):
# Collapse the coordinate by serializing the points and
# bounds as strings.
def serialize(x, axis):
if axis is None or len(axis) == x.ndim:
if axis is None:
return "|".join(str(i) for i in x.flatten())

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

joined = []
for arr_slice in work_array:
Expand Down
18 changes: 9 additions & 9 deletions lib/iris/tests/unit/coords/test_Coord.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,15 @@ def test_lazy_nd_points_and_bounds(self):
self.assertArrayEqual(collapsed_coord.points, da.array([55]))
self.assertArrayEqual(collapsed_coord.bounds, da.array([[-2, 112]]))

def test_string_masked(self):
points = ma.array(["foo", "bar", "bing"], mask=[0, 1, 0], dtype=str)
coord = AuxCoord(points)

collapsed_coord = coord.collapsed(0)

expected = "foo|--|bing"
self.assertEqual(collapsed_coord.points, expected)

def test_string_nd_first(self):
self.setupTestArrays((3, 4))
coord = AuxCoord(self.pts_real.astype(str))
Expand All @@ -484,15 +493,6 @@ def test_string_nd_first(self):

self.assertArrayEqual(collapsed_coord.points, expected)

def test_string_masked(self):
points = ma.array(["foo", "bar", "bing"], mask=[0, 1, 0], dtype=str)
coord = AuxCoord(points)

collapsed_coord = coord.collapsed(0)

expected = "foo|--|bing"
self.assertEqual(collapsed_coord.points, expected)

def test_string_nd_second(self):
self.setupTestArrays((3, 4))
coord = AuxCoord(self.pts_real.astype(str))
Expand Down

0 comments on commit 63b372c

Please sign in to comment.