From d36b713d4fda40d380ddc64d26fc1d11af3d1cb0 Mon Sep 17 00:00:00 2001 From: Romain Hugonnet Date: Thu, 15 Aug 2024 16:30:51 -0800 Subject: [PATCH] Ensure dtype within _interp_points is floating --- geoutils/raster/interpolate.py | 4 ++++ geoutils/raster/raster.py | 1 + 2 files changed, 5 insertions(+) diff --git a/geoutils/raster/interpolate.py b/geoutils/raster/interpolate.py index bb1113a4..40d9ae70 100644 --- a/geoutils/raster/interpolate.py +++ b/geoutils/raster/interpolate.py @@ -247,6 +247,10 @@ def _interp_points( ) -> NDArrayNum | Callable[[tuple[NDArrayNum, NDArrayNum]], NDArrayNum]: """See description of Raster.interp_points.""" + # If array is not a floating dtype (to support NaNs), convert dtype + if not np.issubdtype(array.dtype, np.floating): + array = array.astype(np.float32) + # Get coordinates x, y = points diff --git a/geoutils/raster/raster.py b/geoutils/raster/raster.py index 21ecf3d2..7032ab99 100644 --- a/geoutils/raster/raster.py +++ b/geoutils/raster/raster.py @@ -3636,6 +3636,7 @@ def interp_points( :returns rpoints: Array of raster value(s) for the given points. """ + # Extract array supporting NaNs array = self.get_nanarray() if self.count != 1: array = array[band - 1, :, :]