Skip to content

Commit 8596a72

Browse files
committed
Fix mask in interpolate_2d_nearest in SciPy 1.17.0
1 parent cdec07f commit 8596a72

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

cloudnetpy/utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -417,16 +417,16 @@ def interpolate_2d_nearest(
417417
Points outside the original range will be interpolated but masked.
418418
419419
"""
420-
data = ma.copy(z)
420+
data = ma.filled(z, np.nan)
421421
fun = RegularGridInterpolator(
422422
(x, y),
423423
data,
424424
method="nearest",
425425
bounds_error=False,
426-
fill_value=ma.masked,
427426
)
428427
xx, yy = np.meshgrid(x_new, y_new)
429-
return fun((xx, yy)).T
428+
zz = fun((xx, yy)).T
429+
return ma.masked_where(np.isnan(zz), zz)
430430

431431

432432
def interpolate_2D_along_y(

tests/unit/test_utils.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -362,11 +362,11 @@ def test_interpolate_2d_mask_middle(x_new, y_new, expected):
362362
def test_interpolate_2d_nearest(x_new, y_new, expected):
363363
x = np.array([1, 2, 3])
364364
y = np.array([10, 20])
365-
z = ma.array([[1, 2], [3, 4], [5, 6]], mask=False)
365+
z = ma.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]], mask=False)
366366

367367
result = utils.interpolate_2d_nearest(x, y, z, x_new, y_new)
368-
assert_array_almost_equal(expected.data, result.data)
369368
assert_array_equal(expected.mask, result.mask)
369+
assert_array_almost_equal(expected, result)
370370

371371

372372
@pytest.mark.parametrize(
@@ -388,7 +388,7 @@ def test_interpolate_2d_nearest_2(x_new, y_new, expected):
388388
x = np.array([1, 2, 3, 4, 5])
389389
y = np.array([10, 20])
390390
z = ma.array(
391-
[[1, 2], [3, 4], [5, 6], [7, 8], [9, 10]],
391+
[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0], [7.0, 8.0], [9.0, 10.0]],
392392
mask=[
393393
[False, False],
394394
[False, False],
@@ -399,8 +399,8 @@ def test_interpolate_2d_nearest_2(x_new, y_new, expected):
399399
)
400400

401401
result = utils.interpolate_2d_nearest(x, y, z, x_new, y_new)
402-
assert_array_almost_equal(expected.data, result.data)
403-
assert_array_almost_equal(expected.mask, result.mask)
402+
assert_array_equal(expected.mask, result.mask)
403+
assert_array_almost_equal(expected, result)
404404

405405

406406
class TestArrayToProbability:

0 commit comments

Comments
 (0)