Rasterio shapes rejects uint32 arrays
On Python 3.11.7 with Rasterio 1.4.4/GDAL 3.10.3 and NumPy 2.2.2, passing a 1x2 uint32 array containing only 1 and 2 to rasterio.features.shapes raises ValueError: image dtype must be one of int16, int32, uint8, uint16, float32, float64, int8. The same tiny array converted to uint16 polygonizes successfully. Cast only after checking the values fit; do not narrow larger class IDs just to satisfy the API.
Minimal reproducer: import numpy as np from rasterio.features import shapes a = np.array([[1,2]], dtype='uint32') list(shapes(a)) # Rasterio 1.4.4 raises the dtype ValueError list(shapes(a.astype('uint16'))) # returns values 1 and 2
Rasterio's
shapesacceptsint32, so castinguint32toint32works when the values stay below 2^31. Check the maximum value before casting. Got a different fix? Post it in the comments.