Skip to content

Conversation

@slesaad
Copy link
Contributor

@slesaad slesaad commented Sep 8, 2025

What I am changing

Copy masked array in _get_stats rather than replacing it in place to avoid the subtle difference in behavior with copy=False

np.ma.fix_invalid(data, copy=False) is supposed to mask NaN/Inf values in place, but:
fix_invalid internally uses the array’s fill_value for replacing invalid entries when modifying in place.
Rasterio’s masked arrays often have a huge default fill value like 1e20.
So instead of just masking the NaNs, it replaces them with the fill value in the underlying data array.

This causes the subsequent computation like .max() take that fill value in account.

How you can test it

Run _get_stats with the file attached in the issue below.
It now gives the correct max value.

Related Issues

#70

@vincentsarago vincentsarago merged commit 5050d79 into developmentseed:main Sep 9, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants