Skip to content

Commit e5d7882

Browse files
committed
add and pass bounded tests
1 parent 45ed2f0 commit e5d7882

File tree

2 files changed

+53
-2
lines changed

2 files changed

+53
-2
lines changed

lib/iris/coords.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1973,11 +1973,12 @@ def serialize(x, axis):
19731973
shape = self._bounds_dm.shape[-1:]
19741974
bounds = []
19751975
for index in np.ndindex(shape):
1976-
index_slice = (slice(None),) + tuple(index)
1976+
index_slice = (slice(None),) * self.ndim + tuple(index)
19771977
bounds.append(
19781978
serialize(self.bounds[index_slice], dims_to_collapse)
19791979
)
1980-
bounds = np.array(bounds).reshape((1,) + shape)
1980+
# Make sure bounds dim comes last.
1981+
bounds = np.moveaxis(bounds, 0, -1)
19811982
points = serialize(self.points, dims_to_collapse)
19821983
# Create the new collapsed coordinate.
19831984
coord = self.copy(points=np.array(points), bounds=bounds)

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

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,56 @@ def test_string_nd_second(self):
496496

497497
self.assertArrayEqual(collapsed_coord.points, expected)
498498

499+
def test_string_nd_bounds_first(self):
500+
self.setupTestArrays((3, 4))
501+
coord = AuxCoord(
502+
self.pts_real.astype(str), bounds=self.bds_real.astype(str)
503+
)
504+
505+
collapsed_coord = coord.collapsed(0)
506+
507+
# Points handling is as for non bounded case. So just check bounds.
508+
expected_lower = [
509+
"-2.0|38.0|78.0",
510+
"8.0|48.0|88.0",
511+
"18.0|58.0|98.0",
512+
"28.0|68.0|108.0",
513+
]
514+
515+
expected_upper = [
516+
"2.0|42.0|82.0",
517+
"12.0|52.0|92.0",
518+
"22.0|62.0|102.0",
519+
"32.0|72.0|112.0",
520+
]
521+
522+
self.assertArrayEqual(collapsed_coord.bounds[:, 0], expected_lower)
523+
self.assertArrayEqual(collapsed_coord.bounds[:, 1], expected_upper)
524+
525+
def test_string_nd_bounds_second(self):
526+
self.setupTestArrays((3, 4))
527+
coord = AuxCoord(
528+
self.pts_real.astype(str), bounds=self.bds_real.astype(str)
529+
)
530+
531+
collapsed_coord = coord.collapsed(1)
532+
533+
# Points handling is as for non bounded case. So just check bounds.
534+
expected_lower = [
535+
"-2.0|8.0|18.0|28.0",
536+
"38.0|48.0|58.0|68.0",
537+
"78.0|88.0|98.0|108.0",
538+
]
539+
540+
expected_upper = [
541+
"2.0|12.0|22.0|32.0",
542+
"42.0|52.0|62.0|72.0",
543+
"82.0|92.0|102.0|112.0",
544+
]
545+
546+
self.assertArrayEqual(collapsed_coord.bounds[:, 0], expected_lower)
547+
self.assertArrayEqual(collapsed_coord.bounds[:, 1], expected_upper)
548+
499549

500550
class Test_is_compatible(tests.IrisTest):
501551
def setUp(self):

0 commit comments

Comments
 (0)