Pierre Puiseux
Pierre Puiseux

Reputation: 130

scipy error, but no exception raised

i've encountered a usual scipy.interpolate error :

>>> sx = interpolate.UnivariateSpline(T,X)
  File "...scipy/interpolate/fitpack2.py", line 143, in __init__
    xb=bbox[0],xe=bbox[1],s=s)
dfitpack.error: (m>k) failed for hidden m: fpcurf0:m=3

Is there some Python Exception attached to this error ? (i just want to intercept the exception and ignore it)

If not, how can I do to continue running my program ? Thanks

I'm back a few hours later, to give a solution :

this piece of code, to catch exception and raise my own exception.:

try : 
   sx = interpolate.UnivariateSpline(X,Y)
except : 
   raise PyGlideSplineError("%s : impossible de calculer la spline"%whoami())

It works !!!

Thank you

Upvotes: 3

Views: 1124

Answers (1)

Janne Karila
Janne Karila

Reputation: 25197

scipy.interpolate.dfitpack is an extension that does not seem to expose the exception type directly to Python. However, you can cause a deliberate error to scare the exception from its hiding place, catch it, and store its type in a variable:

from scipy.interpolate import dfitpack

try:
    dfitpack.sproot(-1, -1, -1)
except Exception, e:
    dfitpack_error = type(e)

try:
    dfitpack.sproot(-1, -1, -1)
except dfitpack_error:
    print "Got it!"

Upvotes: 5

Related Questions