Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH : remove an expected warning in BarycentricInterpolator #16857

Merged
merged 4 commits into from Aug 19, 2022

Conversation

tlunet
Copy link
Contributor

@tlunet tlunet commented Aug 18, 2022

Reference issue

See this comment on an other project.

What does this implement/fix?

It remove an expected warning when evaluating a BarycentricInterpolator object (see here...).

The reason why : in the evaluation formula for the barycentric interpolation (see https://parallel-in-time.org/pySDC/pySDC/core.html#module-core.Lagrange), there is a division by zero when an evaluated point coincides with a node. It can be reproduced with the following code :

from scipy.interpolate import BarycentricInterpolator
interp = BarycentricInterpolator([0, 1], [1, 2])
yi = interp(interp.xi)

which outputs :

/prog/anaconda/lib/python3.8/site-packages/scipy/interpolate/_polyint.py:658: RuntimeWarning: divide by zero encountered in true_divide
  p = np.dot(c,self.yi)/np.sum(c,axis=-1)[...,np.newaxis]

Since this division by zero is actually expected and the values corrected later, this PR wraps the line raising the warning with a with np.errstate(divide='ignore'): statement.

Additional information

Spyder IDE specific files added to .gitignore

@tlunet tlunet requested a review from ev-br as a code owner August 18, 2022 08:28
@ev-br ev-br added the maintenance Items related to regular maintenance tasks label Aug 18, 2022
@ev-br ev-br merged commit 3cb1851 into scipy:main Aug 19, 2022
@ev-br
Copy link
Member

ev-br commented Aug 19, 2022

Looks reasonable, thanks @tlunet !

Would be nice to add test in a follow-up PR: use just the reproducer from the OP, with warnings turned to errors.

@ev-br ev-br added this to the 1.10.0 milestone Aug 19, 2022
@ev-br ev-br added this to Done in scipy.interpolate Aug 19, 2022
@tlunet
Copy link
Contributor Author

tlunet commented Aug 19, 2022

Looks reasonable, thanks @tlunet !

Would be nice to add test in a follow-up PR: use just the reproducer from the OP, with warnings turned to errors.

Sure, I can do that. You may just have to explain me what the "reproducer from the OP" is 😅

@ev-br
Copy link
Member

ev-br commented Aug 19, 2022

Meant the three-line code snippet after It can be reproduced with the following code in your original PR message :-).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maintenance Items related to regular maintenance tasks scipy.interpolate
Projects
Development

Successfully merging this pull request may close these issues.

None yet

3 participants