Skip to content

Commit fefbaf6

Browse files
committed
consider masked case
1 parent 2fc1d13 commit fefbaf6

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

lib/iris/coords.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1953,7 +1953,7 @@ def collapsed(self, dims_to_collapse=None):
19531953
# bounds as strings.
19541954
def serialize(x, axis):
19551955
if axis is None:
1956-
return "|".join(x.flatten())
1956+
return "|".join(str(i) for i in x.flatten())
19571957
# np.apply_along_axis does not work with str.join, so we
19581958
# need to loop through the array directly. First move (possibly
19591959
# multiple) axis of interest to trailing dim(s), then make a 2D
@@ -1964,7 +1964,7 @@ def serialize(x, axis):
19641964

19651965
joined = []
19661966
for arr_slice in work_array:
1967-
joined.append("|".join(arr_slice))
1967+
joined.append(serialize(arr_slice, None))
19681968

19691969
return np.array(joined).reshape(out_shape)
19701970

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
import dask.array as da
1717
import numpy as np
18+
import numpy.ma as ma
1819

1920
import iris
2021
from iris.coords import AuxCoord, Coord, DimCoord
@@ -483,6 +484,15 @@ def test_string_nd_first(self):
483484

484485
self.assertArrayEqual(collapsed_coord.points, expected)
485486

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()
492+
493+
expected = "foo|--|bing"
494+
self.assertEqual(collapsed_coord.points, expected)
495+
486496
def test_string_nd_second(self):
487497
self.setupTestArrays((3, 4))
488498
coord = AuxCoord(self.pts_real.astype(str))

0 commit comments

Comments
 (0)