← Back to Pull requests

Preserve masked and NaN fills for NumPy bilinear integer data #762

Open
antonsoo opened this pull request with 26 lines diff across 2 files
View on GitHub
antonsoo antonsoo commented on Oct 24, 2026 15:37 UTC
Author

NumpyBilinearResampler.resample() raises TypeError for integer data with fill_value=None, and ValueError with fill_value=np.nan. The temporary corner array tries to store the output fill before interpolation converts the values to floating point.

Use the existing dtype-safe fill helper for corner slicing, while preserving the requested fill for the final output. This follows the conversion already used by the base resampler. For example, this now returns the expected interpolated values as a masked array:

import numpy as np
from pyresample import create_area_def
from pyresample.geometry import SwathDefinition
from pyresample.bilinear import NumpyBilinearResampler

lons, lats = np.meshgrid([0., 1.], [1., 0.])
source = SwathDefinition(lons=lons, lats=lats)
target = create_area_def('target', 'EPSG:4326', shape=(2, 2),
                         area_extent=(0, 0, 1, 1))
data = np.array([[3, 4], [1, 2]], dtype=np.int16)
r = NumpyBilinearResampler(source, target, 200000,
                          neighbours=4, reduce_data=False)
result = r.resample(data, fill_value=None)
np.testing.assert_allclose(result, [[2.75, 3.25], [1.75, 2.25]])

Validation includes signed/unsigned integer regressions with one and two bands, masked and NaN output, and lookup reuse. Eight previously crashing packed-int16 NCEP reanalysis configurations finish with the same complete output as the floating input; existing controls remain unchanged. This preserves the current interpolation algorithm.

  • Tests added.

  • Original runtime revision: full suite 1,251 passed, 60 skipped; 339 documentation examples pass.

  • Requested pytest parametrization: 77 bilinear tests pass, including both supported area/swath classes. Recorded-data outputs and runtime source hashes are unchanged.

  • Ruff and isort pass. Relevant mypy checks pass in the editable checkout.

  • Native reproduction and combined NumPy 1.26/current-dependency checks pass.
  • Diff: 26 lines (+25 / -1) across 2 files Reviewer: djhoese Review duration: 56590m
    All Vouch review confidence checks passed
    Residual risk 0.03 = Change Risk (0.31) × (1 − Review Confidence (0.90)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.31 · 26 lines diff across 2 files
    0.31
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.92 · 5 substantive comment(s)
    0.92
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 50%
    89%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.197
    Real PR Conversation Timeline
    8 items
    antonsoo antonsoo commented on Oct 24, 2026 15:44 UTC
    Author

    The Read the Docs failure is from four hashlib._Hash annotation warnings in geometry.py and future/resamplers/resampler.py. The same four warnings reproduce on unchanged main 0291a40, and those files and the docs configuration are unchanged by this PR. Existing #760 addresses these annotations.

    Locally, all 339 doctest examples pass on both main and the fixed code. Read the Docs treats the warnings as errors, so its build is still failing; the upstream test workflows await approval.

    djhoese djhoese commented on code on Nov 03, 2026 12:01 UTC
    Code Review
    pyresample/test/test_bilinear.py:1
    @@ -415,6 +415,23 @@ def test_class_resample_method(self):
             self.assertEqual(shp[0:2], self.target_def.shape)
             self.assertEqual(shp[-1], 2)
     
    +    def test_integer_masked_and_nan_output(self):

    While we wait for @pnuu to have time to review this, what do you think about moving this test out of the test class and using pytest's parametrize instead?

    codecov[bot] codecov[bot] commented on Nov 03, 2026 12:32 UTC
    Bot

    Codecov Report


    :white_check_mark: All modified and coverable lines are covered by tests.
    :white_check_mark: Project coverage is 93.92%. Comparing base (4a46786) to head (59c12d2).
    :warning: Report is 24 commits behind head on main.

    <details><summary>Additional details and impacted files</summary>

    @@            Coverage Diff             @@
    ##             main     #762      +/-   ##
    ==========================================
    + Coverage   93.90%   93.92%   +0.02%     
    ==========================================
      Files          89       89              
      Lines       13924    13985      +61     
    ==========================================
    + Hits        13075    13136      +61     
      Misses        849      849              
    

    | Flag | Coverage Δ | |
    |---|---|---|
    | unittests | 93.92% <100.00%> (+0.02%) | :arrow_up: |

    Flags with carried forward coverage won't be shown. Click here to find out more.
    </details>

    :umbrella: View full report in Codecov by Harness.
    :loudspeaker: Have feedback on the report? Share it here.
    <details><summary> :rocket: New features to boost your workflow: </summary>

  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

  • </details>

    pnuu pnuu commented on code on Nov 03, 2026 12:44 UTC
    Code Review
    pyresample/test/test_bilinear.py:1
    @@ -415,6 +415,23 @@ def test_class_resample_method(self):
             self.assertEqual(shp[0:2], self.target_def.shape)
             self.assertEqual(shp[-1], 2)
     
    +    def test_integer_masked_and_nan_output(self):

    I agree, a very good case for paramatrize.

    pnuu pnuu requested changes on Nov 03, 2026 12:47 UTC
    Changes Requested Reviewer

    Thanks for the (surprisingly simple) fix! Back in the day when this was implemented, I think I just considered integer data to be something that shouldn't be resampled with bilinear method, at least for my own usecases, so I hadn't noticed this. It has also been a very long time since I've used this resampler since gradient search works for all my uses and is much more efficient.

    antonsoo antonsoo commented on code on Nov 03, 2026 20:01 UTC
    Code Review
    pyresample/test/test_bilinear.py:1
    @@ -415,6 +415,23 @@ def test_class_resample_method(self):
             self.assertEqual(shp[0:2], self.target_def.shape)
             self.assertEqual(shp[-1], 2)
     
    +    def test_integer_masked_and_nan_output(self):

    Moved it to a module-level pytest test in 6dab7eb, parametrized by dtype, band count and output fill. It uses the shared geometry fixtures, so both supported area/swath classes run, and explicitly reuses the floating run's lookup for the integer input. All 77 bilinear tests pass; Ruff/isort pass. The recorded NCEP replay is unchanged, with all 24 integer configurations completing and all 48 workload records identical to the previous head. Interpolation code is unchanged.

    antonsoo antonsoo commented on Nov 26, 2026 21:01 UTC
    Author

    Gentle ping on this, #763 and #764, in case they got buried. All three still merge cleanly into current main, where the code they change is unchanged. Their CI workflows are waiting for a maintainer's approval to run. Happy to make changes, or to close any that aren't wanted.

    Reviewers
    Assignees
    antonsoo antonsoo
    Labels
    risk: low confidence: 89.8% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 31.2% (LOW) · Higher = larger blast radius
    31.2%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 89.8% · Lower = rushed or shallow review
    89.8%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 3.2% · Safe to merge
    3.2%