From f6796e4e0a7b8f3165ad8e9cd0a6a26746af89bc Mon Sep 17 00:00:00 2001 From: Sam Evans <47793072+Sevans711@users.noreply.github.com> Date: Tue, 10 Nov 2026 14:21:04 -0500 Subject: [PATCH] fix: Grid.__eq__ must check lon AND lat, not "OR" --- test/grid/grid/test_core.py | 17 +++++++++++++++++ uxarray/grid/grid.py | 7 +++---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/test/grid/grid/test_core.py b/test/grid/grid/test_core.py index da5882bea..cc178390b 100644 --- a/test/grid/grid/test_core.py +++ b/test/grid/grid/test_core.py @@ -77,6 +77,23 @@ def test_operators_ne(gridpath): assert grid_mpas != grid_scrip + # Regression test for #1881: == must check lon AND lat, not just one or the other. + # construct some grids with same connectivity, and same lon or same lat, but not both. + lonA = [0, 10, 20, 30] + lonB = [30, 40, 50, 60] + lat0 = [0, 0, 10, 10] + lat1 = [30, 30, 40, 40] + conn = [[0,1,2],[1,2,3]] + gridA0 = ux.Grid.from_topology(node_lon=lonA, node_lat=lat0, face_node_connectivity=conn) + gridA1 = ux.Grid.from_topology(node_lon=lonA, node_lat=lat1, face_node_connectivity=conn) + gridB0 = ux.Grid.from_topology(node_lon=lonB, node_lat=lat0, face_node_connectivity=conn) + gridB1 = ux.Grid.from_topology(node_lon=lonB, node_lat=lat1, face_node_connectivity=conn) + + assert gridA0 != gridA1 + assert gridA0 != gridB0 + assert gridA1 != gridB1 + assert gridB0 != gridB1 + def test_grid_properties(gridpath): """Tests to see if accessing variables through set properties is equal to using the dict.""" diff --git a/uxarray/grid/grid.py b/uxarray/grid/grid.py index 6aa34fbee..1be9f0ed9 100644 --- a/uxarray/grid/grid.py +++ b/uxarray/grid/grid.py @@ -814,11 +814,10 @@ def __eq__(self, other) -> bool: if self.source_grid_spec != other.source_grid_spec: return False - if not ( - self.node_lon.equals(other.node_lon) or self.node_lat.equals(other.node_lat) - ): + if not self.node_lon.equals(other.node_lon): + return False + if not self.node_lat.equals(other.node_lat): return False - if not self.face_node_connectivity.equals(other.face_node_connectivity): return False