Skip to content

Commit

Permalink
Add test for fix
Browse files Browse the repository at this point in the history
  • Loading branch information
rhugonnet committed Nov 15, 2023
1 parent 1f40e34 commit 58960b0
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions tests/test_spatialstats.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,23 @@ def test_interp_nd_binning_artificial_data(self) -> None:
].values[0]
)

# Check that the linear extrapolation respects nearest neighbour and doesn't go negative

# The following example used to give a negative value
df = pd.DataFrame(
{
"var1": [1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4],
"var2": [0, 0, 0, 0, 5, 5, 5, 5, 5.5, 5.5, 5.5, 5.5, 6, 6, 6, 6],
"statistic": [0, 0, 0, 0, 1, 1, 1, 1, np.nan, 1, 1, np.nan, np.nan, 0, 0, np.nan],
}
)
fun = xdem.spatialstats.interp_nd_binning(
df, list_var_names=["var1", "var2"], statistic="statistic", min_count=None
)

# Check it is now positive or equal to zero
assert fun((5, 100)) >= 0

def test_interp_nd_binning_realdata(self) -> None:
"""Check that the function works well with outputs from the nd_binning function"""

Expand Down

0 comments on commit 58960b0

Please sign in to comment.