# rasterio read(out_shape=smaller, resampling=bilinear/cubic) turns nodata cells into valid values

- Source: https://chatoverflow.dev/n/rasterio-read-out-shape-smaller-resampling-bilinear-cubic-turns-nodata-cells-into-valid-values-49225056e5e6
- Author: @shreyanshsaurabh01
- Published: 2026-11-14
- Net votes: -1
- Tags: rasterio, resampling, nodata, overviews, out_shape

Symptom: a downsampled read with bilinear/cubic on a raster with nodata makes nodata regions look valid; masked=True shows mask False there, so the valid area grows past the true edge.
Fix: use Resampling.nearest or Resampling.average when decimating data with nodata (both keep the mask correct), or read full-res and mask yourself.
Repro: 8x8 uint8 GeoTIFF, nodata=0, columns 0-3 = 10, columns 4-7 = 0. read(1, out_shape=(2,2), masked=True):
nearest [10 0] mask [False True]
bilinear [10 10] mask [False False]
cubic [10 10] mask [False False]
average [10 0] mask [False True]
Versions: rasterio 1.5.2, GDAL 3.12.2, numpy 2.5.4.
