Skip to content

Robust nodata detection in raster builders#853

Open
Omiii-215 wants to merge 4 commits into
pysal:mainfrom
Omiii-215:fix/741-robust-nodata
Open

Robust nodata detection in raster builders#853
Omiii-215 wants to merge 4 commits into
pysal:mainfrom
Omiii-215:fix/741-robust-nodata

Conversation

@Omiii-215
Copy link
Copy Markdown

The justification for this PR is:

  • Handle NaNs explicitly in masking logic for float rasters
  • Fix fallback path to respect generated masks (e.g. from NaN or rio.nodata)
  • Add regression tests for NaN handling and rioxarray compatibility

- Handle NaNs explicitly in masking logic for float rasters
- Fix fallback path to respect generated masks (e.g. from NaN or rio.nodata)
- Add regression tests for NaN handling and rioxarray compatibility
@codecov
Copy link
Copy Markdown

codecov Bot commented Jan 21, 2026

Codecov Report

❌ Patch coverage is 98.27586% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 85.5%. Comparing base (dbbd194) to head (6e45311).
⚠️ Report is 7 commits behind head on main.

Files with missing lines Patch % Lines
libpysal/weights/raster.py 91.7% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@          Coverage Diff          @@
##            main    #853   +/-   ##
=====================================
  Coverage   85.5%   85.5%           
=====================================
  Files        151     151           
  Lines      16091   16145   +54     
=====================================
+ Hits       13756   13810   +54     
  Misses      2335    2335           
Files with missing lines Coverage Δ
libpysal/weights/tests/test_raster.py 100.0% <100.0%> (ø)
libpysal/weights/raster.py 61.1% <91.7%> (+0.6%) ⬆️

... and 3 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@sjsrey
Copy link
Copy Markdown
Member

sjsrey commented Jan 21, 2026

Hi @Omiii-215 and thank you for this PR.

Because we are now receiving many GSOC related PRs and Issues, we have updated our GSOC Contribution Policy and would ask all participants to please review it. As this PR is not targeted at a priority project for GSOC this year, we will leave this open for the maintainers to consider when they have time, but it won't be a priority for GSOC consideration.

@Omiii-215 Omiii-215 changed the title Fix #741: Robust nodata detection in raster builders Robust nodata detection in raster builders Jan 22, 2026
Copy link
Copy Markdown
Member

@martinfleis martinfleis left a comment

Choose a reason for hiding this comment

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

Not sure I follow this properly but is there actually anything that would fail without these changes? Seems to me that it essentially does anything no? Masks out np.nan to replace it with np.nan...

@Omiii-215
Copy link
Copy Markdown
Author

mask = values != nodata failed for nan because np.nan != np.nan evaluates to True? because of this only i think nan pixels were to be treated as valid data, np.isnan(values) handles nan. The test failure confirms that without this fix, nans incorrectly leak into the weights object.

- Changed comparison logic to ~np.isnan() to fix np.nan != np.nan issue
- Added support for numpy scalar NaNs
- Added new tests for edge cases
@Omiii-215 Omiii-215 requested a review from martinfleis January 29, 2026 06:02
@Omiii-215
Copy link
Copy Markdown
Author

i have improved the handling and added some new tests to remove the robustness

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.

3 participants