From c2414bbf09a951515adc0248ecd420b884a7f83f Mon Sep 17 00:00:00 2001 From: thodson-usgs Date: Fri, 17 Apr 2026 16:25:23 -0500 Subject: [PATCH] Fix three latent bugs in Grid construction and mode regridders - utils.create_lat_lon_coords: check remainder against resolution_lon (not resolution_lat) for the longitude span, so non-square grids no longer overshoot `east`. - Grid.__post_init__: the `south > north` branch now reports the correct bound in the error message, and the second check uses `elif` so the first failure isn't silently overwritten. Drops a stray `pass`. - regrid.most_common / regrid.least_common: the Dataset-input error message was a tuple (trailing comma on the first string literal), so ValueError printed unreadably. Remove the comma so the message is a single string. --- src/xarray_regrid/regrid.py | 8 ++++---- src/xarray_regrid/utils.py | 7 +++---- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/xarray_regrid/regrid.py b/src/xarray_regrid/regrid.py index b2ed389..d34eb72 100644 --- a/src/xarray_regrid/regrid.py +++ b/src/xarray_regrid/regrid.py @@ -164,10 +164,10 @@ def most_common( if isinstance(self._obj, xr.Dataset): msg = ( - "The 'most common value' regridder is not implemented for\n", + "The 'most common value' regridder is not implemented for\n" "xarray.Dataset, as it requires specifying the expected labels.\n" "Please select only a single variable (as DataArray),\n" - " and regrid it separately.", + " and regrid it separately." ) raise ValueError(msg) @@ -216,10 +216,10 @@ def least_common( if isinstance(self._obj, xr.Dataset): msg = ( - "The 'least common value' regridder is not implemented for\n", + "The 'least common value' regridder is not implemented for\n" "xarray.Dataset, as it requires specifying the expected labels.\n" "Please select only a single variable (as DataArray),\n" - " and regrid it separately.", + " and regrid it separately." ) raise ValueError(msg) diff --git a/src/xarray_regrid/utils.py b/src/xarray_regrid/utils.py index 6979f84..0e4d2db 100644 --- a/src/xarray_regrid/utils.py +++ b/src/xarray_regrid/utils.py @@ -31,11 +31,10 @@ def __post_init__(self) -> None: msg = None if self.south > self.north: msg = ( - "Value of north bound is greater than south bound." + "Value of south bound is greater than north bound." "\nPlease check the bounds input." ) - pass - if self.west > self.east: + elif self.west > self.east: msg = ( "Value of west bound is greater than east bound." "\nPlease check the bounds input." @@ -80,7 +79,7 @@ def create_lat_lon_coords(grid: Grid) -> tuple[np.ndarray, np.ndarray]: grid.south, grid.north + grid.resolution_lat, grid.resolution_lat ) - if np.remainder((grid.east - grid.west), grid.resolution_lat) > 0: + if np.remainder((grid.east - grid.west), grid.resolution_lon) > 0: lon_coords = np.arange(grid.west, grid.east, grid.resolution_lon) else: lon_coords = np.arange(