@@ -332,7 +332,8 @@ def test_dim_1d(self):
332332 )
333333 for units in ["unknown" , "no_unit" , 1 , "K" ]:
334334 coord .units = units
335- collapsed_coord = coord .collapsed ()
335+ with self .assertNoWarningsRegexp ():
336+ collapsed_coord = coord .collapsed ()
336337 self .assertArrayEqual (
337338 collapsed_coord .points , np .mean (coord .points )
338339 )
@@ -474,6 +475,98 @@ def test_lazy_nd_points_and_bounds(self):
474475 self .assertArrayEqual (collapsed_coord .points , da .array ([55 ]))
475476 self .assertArrayEqual (collapsed_coord .bounds , da .array ([[- 2 , 112 ]]))
476477
478+ def test_numeric_nd_multidim_bounds_warning (self ):
479+ self .setupTestArrays ((3 , 4 ))
480+ coord = AuxCoord (self .pts_real , bounds = self .bds_real , long_name = "y" )
481+
482+ msg = (
483+ "Collapsing a multi-dimensional coordinate. "
484+ "Metadata may not be fully descriptive for 'y'."
485+ )
486+ with self .assertWarnsRegex (UserWarning , msg ):
487+ coord .collapsed ()
488+
489+ def test_lazy_nd_multidim_bounds_warning (self ):
490+ self .setupTestArrays ((3 , 4 ))
491+ coord = AuxCoord (self .pts_lazy , bounds = self .bds_lazy , long_name = "y" )
492+
493+ msg = (
494+ "Collapsing a multi-dimensional coordinate. "
495+ "Metadata may not be fully descriptive for 'y'."
496+ )
497+ with self .assertWarnsRegex (UserWarning , msg ):
498+ coord .collapsed ()
499+
500+ def test_numeric_nd_noncontiguous_bounds_warning (self ):
501+ self .setupTestArrays ((3 ))
502+ coord = AuxCoord (self .pts_real , bounds = self .bds_real , long_name = "y" )
503+
504+ msg = (
505+ "Collapsing a non-contiguous coordinate. "
506+ "Metadata may not be fully descriptive for 'y'."
507+ )
508+ with self .assertWarnsRegex (UserWarning , msg ):
509+ coord .collapsed ()
510+
511+ def test_lazy_nd_noncontiguous_bounds_warning (self ):
512+ self .setupTestArrays ((3 ))
513+ coord = AuxCoord (self .pts_lazy , bounds = self .bds_lazy , long_name = "y" )
514+
515+ msg = (
516+ "Collapsing a non-contiguous coordinate. "
517+ "Metadata may not be fully descriptive for 'y'."
518+ )
519+ with self .assertWarnsRegex (UserWarning , msg ):
520+ coord .collapsed ()
521+
522+ def test_numeric_3_bounds (self ):
523+
524+ points = np .array ([2.0 , 6.0 , 4.0 ])
525+ bounds = np .array ([[1.0 , 0.0 , 3.0 ], [5.0 , 4.0 , 7.0 ], [3.0 , 2.0 , 5.0 ]])
526+
527+ coord = AuxCoord (points , bounds = bounds , long_name = "x" )
528+
529+ msg = (
530+ r"Cannot check if coordinate is contiguous: Invalid operation for "
531+ r"'x', with 3 bound\(s\). Contiguous bounds are only defined for "
532+ r"1D coordinates with 2 bounds. Metadata may not be fully "
533+ r"descriptive for 'x'. Ignoring bounds."
534+ )
535+ with self .assertWarnsRegex (UserWarning , msg ):
536+ collapsed_coord = coord .collapsed ()
537+
538+ self .assertFalse (collapsed_coord .has_lazy_points ())
539+ self .assertFalse (collapsed_coord .has_lazy_bounds ())
540+
541+ self .assertArrayAlmostEqual (collapsed_coord .points , np .array ([4.0 ]))
542+ self .assertArrayAlmostEqual (
543+ collapsed_coord .bounds , np .array ([[2.0 , 6.0 ]])
544+ )
545+
546+ def test_lazy_3_bounds (self ):
547+
548+ points = da .arange (3 ) * 2.0
549+ bounds = da .arange (3 * 3 ).reshape (3 , 3 )
550+
551+ coord = AuxCoord (points , bounds = bounds , long_name = "x" )
552+
553+ msg = (
554+ r"Cannot check if coordinate is contiguous: Invalid operation for "
555+ r"'x', with 3 bound\(s\). Contiguous bounds are only defined for "
556+ r"1D coordinates with 2 bounds. Metadata may not be fully "
557+ r"descriptive for 'x'. Ignoring bounds."
558+ )
559+ with self .assertWarnsRegex (UserWarning , msg ):
560+ collapsed_coord = coord .collapsed ()
561+
562+ self .assertTrue (collapsed_coord .has_lazy_points ())
563+ self .assertTrue (collapsed_coord .has_lazy_bounds ())
564+
565+ self .assertArrayAlmostEqual (collapsed_coord .points , da .array ([2.0 ]))
566+ self .assertArrayAlmostEqual (
567+ collapsed_coord .bounds , da .array ([[0.0 , 4.0 ]])
568+ )
569+
477570
478571class Test_is_compatible (tests .IrisTest ):
479572 def setUp (self ):
0 commit comments