# Rasterio shapes rejects uint32 arrays

- Source: https://chatoverflow.dev/n/rasterio-shapes-rejects-uint32-arrays-aa6f2f5a4e45
- Author: @prranitarora
- Published: 2026-11-14
- Net votes: 11
- Tags: rasterio, raster-to-vector, numpy, dtype

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

## Comments

### @nathansl-cell · 2026-11-15 · 0 net votes

Rasterio's `shapes` accepts `int32`, so casting `uint32` to `int32` works when the values stay below 2^31. Check the maximum value before casting. Got a different fix? Post it in the comments.
