-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
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: special: allow for more fine-tuned error handling #6753
Conversation
@ev-br when you have the chance, I wonder if you could comment on whether you find this more pleasant to use than the current |
# Match to clpmn; DLMF 14.9.13 | ||
fixarr = where(mf > nf, 0.0, gamma(nf-mf+1) / gamma(nf+mf+1)) | ||
sv = errprint(sv) | ||
with ufuncs.errstate(all='ignore'): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor, non-blocking: what's the reason to import it from private _ufuncs
rather than public from scipy.special import errstate
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably not a good one. The imports at the top also import things from _ufuncs
and I was trying to be consistent, but probably everything should just be cleaned up to use special
instead. There are a couple of other spots like that lurking in the special tests. I wonder what the history is?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I looked at git blame a bit down to
a6270c97 Lib/special/basic.py (Travis Oliphant 2005-10-06 03:09:02 +0000 6) from _cephes import *
then on to
f41c1dae scipy/special/basic.py (Warren Weckesser 2010-11-20 16:49:57 +0000 8) from _cephes import ellipk, mathieu_a, mathieu_b, iv, jv, gamma, psi, zeta, \
and
da453dca scipy/special/basic.py (Martin Teichmann 2011-08-11 09:17:31 +0200 8) from _cephes import ellipkm1, mathieu_a, mathieu_b, iv, jv, gamma, psi, zeta, \
and then _cephes
becomes _ufuncs
:
08b56a03 scipy/special/basic.py (Pauli Virtanen 2012-10-07 04:07:09 +0300 9) from _ufuncs import ellipkm1, mathieu_a, mathieu_b, iv, jv, gamma, psi, zeta, \
followed by the Python 3 transition where the import becomes from ._ufuncs import ...
also in 2012.
So yeah, it has always been like that :-), and I'm not sure there's much point messing with it. Scratch my comment above :-).
The I'm not sure if it's worth it to add a pair of geterr and seterr. I'd guess that numpy only has this pair because it predates the introduction of context managers in python. However I don't have a very strong opinion here, and I defer to you and Pauli on this and on whether to formally deprecate The changes to |
I do think there's one use case for |
Indeed. |
Can you rebase it please @person142 |
Will do, but need to fix #6972 first. |
Add new functions `geterr` and `seterr` and a context manager `errstate` that control how special-function errors are handled. There are now several categories of errors: - singular - underflow - overflow - slow - loss - no_result - domain - arg - other which can each individually be set to 'ignore', 'warn', or 'raise'. This allows one to e.g. raise on interesting errors like loss of precision while ignoring fairly routine errors like underflow. The new functions/context manager work similarly to the eponymous NumPy functions/context manager. Closes scipygh-6681.
12fd6e2
to
4a99117
Compare
Rebased; hopefully nothing breaks. |
Merging, thanks Josh! |
Add new functions
geterr
andseterr
and a context managererrstate
that control how special-function errors are handled. Thereare now several categories of errors:
which can each individually be set to 'ignore', 'warn', or
'raise'. This allows one to e.g. raise on interesting errors like loss
of precision while ignoring fairly routine errors like underflow.
The new functions/context manager work similarly to the eponymous
NumPy functions/context manager.
Closes gh-6681.
Example: