
On 4/29/11 5:50 PM, Alexander Belopolsky wrote:
On Fri, Apr 29, 2011 at 5:30 PM, Alexander Belopolsky <alexander.belopolsky@gmail.com> wrote: ..
As I mentioned before, Python does not have a mechanism that would allow to simultaneously raise an exception and deliver the result. We have to choose one or the other.
I made this argument several times and it went unchallenged, but I now realize that Python does have a mechanism that would allow to simultaneously raise an exception and deliver the result. This is what warnings do. Since changing NaN< 0 to raise an error would have to be done by issuing a deprecation warning first, why can't we just issue appropriate warning on invalid operations? Isn't this what numpy does in some cases?
We have a configurable mechanism that lets you change between ignoring, warning, and raising an exception (and a few others). [~] |1> with np.errstate(invalid='raise'): ..> np.array([np.inf]) / np.array([np.inf]) ..> --------------------------------------------------------------------------- FloatingPointError Traceback (most recent call last) /Users/rkern/<ipython-input-1-d0b8f36f6dea> in <module>() 1 with np.errstate(invalid='raise'): ----> 2 np.array([np.inf]) / np.array([np.inf]) 3 FloatingPointError: invalid value encountered in divide [~] |2> with np.errstate(invalid='ignore'): ..> np.array([np.inf]) / np.array([np.inf]) ..> [~] |3> with np.errstate(invalid='warn'): ..> np.array([np.inf]) / np.array([np.inf]) ..> /Library/Frameworks/Python.framework/Versions/Current/bin/ipython:2: RuntimeWarning: invalid value encountered in divide I think I could support issuing a warning. Beats the hell out of arguing over fine details of ancient standards intended for low-level languages and hardware. :-) -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco