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

Check for non-numeric keys in value_map in reclassify raster function #419 #420

Merged
merged 4 commits into from
Dec 19, 2024

Conversation

claire-simpson
Copy link
Contributor

Check that the value_map does not contain any non-numeric keys in the raster reclassify function. This function will fail if there are any None/NA keys in the value_map dictionary so instead we're explicitly checking for them upfront to provide the user with a clearer error message. Note that this still allows numpy.nan keys to pass. I've also created a test to confirm this check works as anticipated.

Fixes #419

Copy link
Contributor

@davemfish davemfish left a comment

Choose a reason for hiding this comment

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

Thanks, @claire-simpson , this is very succinct and effective. Would you please add a note in HISTORY about the new TypeError being raised? And I found one little redundant line in the test.

tests/test_geoprocessing.py Outdated Show resolved Hide resolved
@claire-simpson
Copy link
Contributor Author

Thanks @davemfish! I noticed that many of the geoprocessing tests define the target_nodata two times, may be something to look into?

@davemfish
Copy link
Contributor

Thanks @davemfish! I noticed that many of the geoprocessing tests define the target_nodata two times, may be something to look into?

Interesting, feel free to clean that up for us if you'd like to! It could happen in this PR if you want, or a separate one.

@claire-simpson
Copy link
Contributor Author

Interesting, feel free to clean that up for us if you'd like to! It could happen in this PR if you want, or a separate one.

Went ahead and did it. I suspect target_nodata was redefined explicitly as the function called in between the duplicate assignments did set target_nodata but that should be out of scope and therefore unnecessary to reassign target_nodata in the test script

@davemfish
Copy link
Contributor

Went ahead and did it. I suspect target_nodata was redefined explicitly as the function called in between the duplicate assignments did set target_nodata but that should be out of scope and therefore unnecessary to reassign target_nodata in the test script

Thank you!

@davemfish davemfish merged commit a9fe8df into natcap:main Dec 19, 2024
63 checks passed
@claire-simpson claire-simpson deleted the check-na-key branch December 19, 2024 19:57
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.

Provide better error handling for NA/NaN keys in value map in reclassify raster function
2 participants