Skip to content

Commit da8af99

Browse files
committed
always use masked array for stats
1 parent 7a5efaf commit da8af99

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

raster_loader/io/common.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,8 @@ def raster_band_stats(raster_dataset: rasterio.io.DatasetReader, band: int) -> d
327327
and not band_is_float(raster_dataset, band)
328328
):
329329
masked = False
330-
stats = raster_dataset.read(band)
330+
unmasked_data = raster_dataset.read(band)
331+
stats = np.ma.masked_array(data=unmasked_data, mask=False)
331332
else:
332333
masked = True
333334
if alpha_band:
@@ -369,9 +370,9 @@ def raster_band_stats(raster_dataset: rasterio.io.DatasetReader, band: int) -> d
369370
"quantiles": quantiles,
370371
"top_values": most_common,
371372
"version": version,
372-
"count": np.count_nonzero(stats.mask is False)
373-
if masked
374-
else math.prod(stats.shape), # noqa: E712
373+
"count": (
374+
np.count_nonzero(stats.mask is False) if masked else math.prod(stats.shape)
375+
), # noqa: E712
375376
}
376377

377378

0 commit comments

Comments
 (0)