Skip to content

Commit

Permalink
Fix: OverflowError error when casting approx sum to integer
Browse files Browse the repository at this point in the history
  • Loading branch information
rantolin committed Jan 10, 2025
1 parent f9f5ff5 commit 46cab53
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions raster_loader/io/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@ def get_color_table(raster_dataset: rasterio.io.DatasetReader, band: int):
return None



def rasterio_metadata(
file_path: str,
bands_info: List[Tuple[int, str]],
Expand Down Expand Up @@ -424,7 +423,12 @@ def not_enough_samples():
)
if not raster_is_masked:
for band in bands:
not_masked_samples[band].append(sample[band - 1])
band_sample = sample[band - 1]
is_valid_sample = not (
np.isinf(band_sample) or np.isnan(band_sample)
)
if is_valid_sample:
not_masked_samples[band].append(band_sample)

iterations += 1

Expand Down Expand Up @@ -507,8 +511,14 @@ def raster_band_approx_stats(
_sum = 0
sum_squares = 0
if count > 0:
_sum = int(np.sum(samples_band))
sum_squares = int(np.sum(np.array(samples_band) ** 2))
try:
_sum = int(np.sum(samples_band))
except (OverflowError, ValueError):
_sum = 0
try:
sum_squares = int(np.sum(np.array(samples_band) ** 2))
except (OverflowError, ValueError):
sum_squares = 0

if basic_stats:
quantiles = None
Expand Down

0 comments on commit 46cab53

Please sign in to comment.