From 23b0eebcfb6317019e2147fb58b76490fb3e0ea7 Mon Sep 17 00:00:00 2001 From: Rajeev Jain Date: Thu, 14 May 2026 10:38:36 -0500 Subject: [PATCH 1/2] Fix to_polycollection exclude path: always cache antimeridian_face_indices Fixes #1507 When to_polycollection is called without a projection, antimeridian_face_indices was computed but never written to _poly_collection_cached_parameters, leaving the cache entry as None. dataarray.to_polycollection then called np.delete(data, None, axis=0), which became a hard IndexError in numpy 2.0 (previously a silent no-op or deprecation warning). Move the cache write to before the projection-only block so the entry is always populated regardless of whether a projection is supplied. --- uxarray/grid/geometry.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/uxarray/grid/geometry.py b/uxarray/grid/geometry.py index b7a0c5c51..670bcc5f6 100644 --- a/uxarray/grid/geometry.py +++ b/uxarray/grid/geometry.py @@ -495,6 +495,13 @@ def _grid_to_matplotlib_polycollection( polygon_shells[:, :, 0] ) + # Always cache antimeridian_face_indices; dataarray.to_polycollection reads it + # regardless of whether a projection is used. Without this, the cache entry + # stays None and np.delete raises IndexError on numpy >= 2.0. + grid._poly_collection_cached_parameters["antimeridian_face_indices"] = ( + antimeridian_face_indices + ) + # Filter out NaN-containing polygons if projection is applied non_nan_polygon_indices = None if projected_polygon_shells is not None: @@ -510,9 +517,6 @@ def _grid_to_matplotlib_polycollection( grid._poly_collection_cached_parameters["non_nan_polygon_indices"] = ( non_nan_polygon_indices ) - grid._poly_collection_cached_parameters["antimeridian_face_indices"] = ( - antimeridian_face_indices - ) # Select which shells to use: projected or original if projected_polygon_shells is not None: From 3276b75ff7b6072b3638d241e4965988cd3557e7 Mon Sep 17 00:00:00 2001 From: Rajeev Jain Date: Thu, 14 May 2026 11:23:40 -0500 Subject: [PATCH 2/2] Restore both cache writes outside projection if-block PR #1454 accidentally moved both non_nan_polygon_indices and antimeridian_face_indices cache writes inside the projection check. Move them back out unconditionally, restoring the pre-#1454 behavior. --- uxarray/grid/geometry.py | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/uxarray/grid/geometry.py b/uxarray/grid/geometry.py index 670bcc5f6..6d54ec971 100644 --- a/uxarray/grid/geometry.py +++ b/uxarray/grid/geometry.py @@ -495,13 +495,6 @@ def _grid_to_matplotlib_polycollection( polygon_shells[:, :, 0] ) - # Always cache antimeridian_face_indices; dataarray.to_polycollection reads it - # regardless of whether a projection is used. Without this, the cache entry - # stays None and np.delete raises IndexError on numpy >= 2.0. - grid._poly_collection_cached_parameters["antimeridian_face_indices"] = ( - antimeridian_face_indices - ) - # Filter out NaN-containing polygons if projection is applied non_nan_polygon_indices = None if projected_polygon_shells is not None: @@ -514,9 +507,12 @@ def _grid_to_matplotlib_polycollection( does_not_contain_nan = ~np.isnan(shells_d).any(axis=(1, 2)) non_nan_polygon_indices = np.where(does_not_contain_nan)[0] - grid._poly_collection_cached_parameters["non_nan_polygon_indices"] = ( - non_nan_polygon_indices - ) + grid._poly_collection_cached_parameters["non_nan_polygon_indices"] = ( + non_nan_polygon_indices + ) + grid._poly_collection_cached_parameters["antimeridian_face_indices"] = ( + antimeridian_face_indices + ) # Select which shells to use: projected or original if projected_polygon_shells is not None: