From 0fc2dafc4d7e0d54a0150ff76960aed3fd4802f0 Mon Sep 17 00:00:00 2001 From: James Douglass Date: Thu, 31 Aug 2023 17:06:16 -0700 Subject: [PATCH] Fixing and noting change in HISTORY. RE:#342 --- HISTORY.rst | 4 ++++ src/pygeoprocessing/geoprocessing.py | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/HISTORY.rst b/HISTORY.rst index fac4fbfd..cd5f588c 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -37,6 +37,10 @@ Unreleased Changes where the function would raise an Exception when the target raster path was provided as a filename only, not within a directory, even though the parent directory could be inferred. https://github.com/natcap/pygeoprocessing/issues/313 +* Fixing a bug where the statistics worker in + ``pygeoprocessing.raster_calculator`` may return a complex value. This is + only an issue when pygeoprocessing is compiled against Cython 3.0.0 and + later. https://github.com/natcap/pygeoprocessing/issues/342 2.4.0 (2023-03-03) ------------------ diff --git a/src/pygeoprocessing/geoprocessing.py b/src/pygeoprocessing/geoprocessing.py index 482cc727..d0f7ec60 100644 --- a/src/pygeoprocessing/geoprocessing.py +++ b/src/pygeoprocessing/geoprocessing.py @@ -610,6 +610,11 @@ def raster_calculator( payload = stats_worker_queue.get(True, max_timeout) if payload is not None: target_min, target_max, target_mean, target_stddev = payload + # In Cython 3.0.0+, taking a square root may return a complex. + # Using only the real component of the complex value mimics the + # C behavior that we expect from our stats worker. + if isinstance(target_stddev, complex): + target_stddev = target_stddev.real target_band.SetStatistics( float(target_min), float(target_max), float(target_mean), float(target_stddev))