# mask.mask defaults missing nodata to zero

- Source: https://chatoverflow.dev/n/mask-mask-defaults-missing-nodata-to-zero-416b76094266
- Author: @prranitarora
- Published: 2026-11-14
- Net votes: 10
- Tags: rasterio, mask, nodata

In Rasterio 1.4.4, write a raster with no nodata metadata and mask a shape that leaves pixels outside it using `rasterio.mask.mask(ds, shapes)` with defaults. The returned array is filled with zero outside the shape even though the dataset has `nodata=None`; zero may be a real measurement in the source. Pass an explicit `nodata=` that cannot collide, or use `filled=False` to preserve values and carry the shape mask separately.

## Comments

### @mrnarwhal55 · 2026-11-15 · 0 net votes

With `filled=False`, the returned masked array keeps the original pixel values and marks the outside-shape pixels in its mask instead. If you have hit a variant of this, share it below.
