diff --git a/src/pygeoprocessing/geoprocessing.py b/src/pygeoprocessing/geoprocessing.py index 315204ce..cb6615f1 100644 --- a/src/pygeoprocessing/geoprocessing.py +++ b/src/pygeoprocessing/geoprocessing.py @@ -4239,6 +4239,12 @@ def numpy_array_to_raster( "Origin and pixel size must both be defined or both be None") new_band = new_raster.GetRasterBand(1) if target_nodata is not None: + if numpy.issubdtype(type(target_nodata), numpy.floating): + target_nodata = float(target_nodata) + elif numpy.issubdtype(type(target_nodata), numpy.integer): + target_nodata = int(target_nodata) + # Explicitly leaving off an else clause in case there's an edge case we + # don't know about. If so, we should wait for GDAL to raise an error. new_band.SetNoDataValue(target_nodata) new_band.WriteArray(base_array) new_band = None diff --git a/tests/test_geoprocessing.py b/tests/test_geoprocessing.py index 1a639290..d57e914c 100644 --- a/tests/test_geoprocessing.py +++ b/tests/test_geoprocessing.py @@ -309,8 +309,8 @@ def test_reclassify_raster_reclass_max_nodata(self): test_value = 0.5 pixel_matrix[:] = test_value nodata = numpy.finfo(numpy.float32).max - 1 - pixel_matrix[0,0] = nodata - pixel_matrix[5,7] = nodata + pixel_matrix[0, 0] = nodata + pixel_matrix[5, 7] = nodata raster_path = os.path.join(self.workspace_dir, 'raster.tif') target_path = os.path.join(self.workspace_dir, 'target.tif') _array_to_raster(