Skip to content

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

Open
antonsoo wants to merge 1 commit into
pytroll:mainfrom
antonsoo:fix/numpy-bilinear-integer-fill
Open

antonsoo wants to merge 1 commit into
pytroll:mainfrom
antonsoo:fix/numpy-bilinear-integer-fill

Conversation

@antonsoo

Copy link
Copy Markdown

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.
  • Full suite: 1,251 passed, 60 skipped; 339 documentation examples pass.
  • Ruff and isort pass. Relevant mypy checks pass in the editable checkout.
  • Native reproduction and combined NumPy 1.26/current-dependency checks pass.

@antonsoo

Copy link
Copy Markdown
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.

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.

1 participant