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

raster_map errors on valid combinations of dtype and nodata value #358

Open
emlys opened this issue Nov 2, 2023 · 1 comment · May be fixed by #408
Open

raster_map errors on valid combinations of dtype and nodata value #358

emlys opened this issue Nov 2, 2023 · 1 comment · May be fixed by #408
Labels
bug Something isn't working
Milestone

Comments

@emlys
Copy link
Member

emlys commented Nov 2, 2023

If target_dtype and target_nodata are provided to raster_map, it tries to confirm that the nodata value fits into the dtype using numpy.can_cast. This does not work as I expected:

>>> float32_min = float(numpy.finfo(numpy.float32).min)
>>> numpy.can_cast(float32_min, numpy.float32)
False

It's usually not necessary to set the target_dtype and target_nodata, but this bug prevents us from doing so in some cases.

@emlys emlys added the bug Something isn't working label Nov 2, 2023
@dcdenu4
Copy link
Member

dcdenu4 commented Nov 6, 2023

Interesting. This looks like an issue with casting to float.

>>> numpy.can_cast(numpy.finfo(numpy.float32).min, numpy.float32)
True
>>> numpy.can_cast(float(numpy.finfo(numpy.float32).min), numpy.float32)
False
>>> numpy.can_cast(float(numpy.finfo(numpy.float32).min), numpy.float64)
True

So casting with float is returning a float64 type!

Using casting=same_kind works though.

>>> numpy.can_cast(float(numpy.finfo(numpy.float32).min), numpy.float32, "same_kind")
True

‘same_kind’ means only safe casts or casts within a kind, like float64 to float32, are allowed.

phargogh added a commit to phargogh/pygeoprocessing that referenced this issue Oct 10, 2024
phargogh added a commit to phargogh/pygeoprocessing that referenced this issue Oct 10, 2024
phargogh added a commit to phargogh/pygeoprocessing that referenced this issue Oct 10, 2024
@phargogh phargogh modified the milestones: 2.4.6, 2.4.7 Oct 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants