Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make astype set new nodata by default, and data.setter check for unmasked nodata #472

Merged
merged 8 commits into from
Feb 5, 2024

Conversation

rhugonnet
Copy link
Member

@rhugonnet rhugonnet commented Feb 1, 2024

That little change on astype ended up being a lot bigger than I anticipated!

I realized that:

What's changed

  1. At the end of data.setter, we now check that there isn't any nodata value that is unmasked, otherwise we mask them (in case it is user input and not numerics) BUT RAISE A WARNING and recommend the user to either: Mask his array when creating the raster (if that was what he was doing), or Change the dtype to not have numerical operation derive the nodata value (if that was what he was doing). This mostly happens with int, and should be very easy to silence using a float array with properly masked values (or NaNs).
  2. Changes the nodata when using astype by default. If the nodata is already in the array, it will be detected by set_nodata().

Surprisingly, those two "big" changes didn't create so many new errors in tests, and actually rather allowed to identify a couple bugs! 😄
The rest is adding new tests, silencing or catching warnings, and updating the warning for the nodata setter (that were still not so clear when I re-read them).

Resolves #471
Resolves #470
Resolves #469
Resolves #394

@rhugonnet rhugonnet requested a review from adehecq February 1, 2024 22:36
tests/test_raster.py Outdated Show resolved Hide resolved
Copy link
Member

@adehecq adehecq left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job finding all these bugs !
I went quickly through the tests, but the changes make sense.

@rhugonnet rhugonnet merged commit b9b5a0f into GlacioHack:main Feb 5, 2024
13 checks passed
@rhugonnet rhugonnet deleted the astype_nodata branch February 5, 2024 14:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment