Can an OpenTURNS PythonFunction transmit exceptions from the Python function?

Hi,

I ran recently in a problem using an OpenTURNS PythonFunction, which I reproduce here in a simplified form:

I created the following PythonFunction

import openturns as ot
import numpy as np

def myfunc( x ):
    return x[:1] / x[1:]

my_OTfunc = ot.PythonFunction( 2, 1, myfunc )

Note my mistake: the division operator “/” does not apply to ot.Point objects, so the above code has every reason to crash. However, I tested my code by typing:

x = np.array([1, 2])
myfunc( x )
my_OTfunc ( x )

The Python function myfunc worked well because it operated on a np.array. The OpenTURNS Python Function my_OTfunc crashed, because it first converted the numpy array into a ot.Point. This means that myfunc actually returned the exception obtained by typing:

myfunc( ot.Point(x) ),

which is:

TypeError: unsupported operand type(s) for /: 'Point' and 'Point'

However, the only exception I got was:

RuntimeError: InternalException : Python exception

which is rather poorly informative; it then took me (at least) twenty minutes to realize my mistake. Which leads to my question: would it be possible to modify the ot.PythonFunction structure so that it transmits the exceptions raised by the Python Function it is built upon?

Many thanks in advance for your answer,

Best
Merlin

its a bug with the 1.24 with recent Python it seems, I fixed it a few weeks ago in my misc branch:

RuntimeError: InternalException : Python exception: <class 'TypeError'>: sequence index must be integer, not 'slice'

which version of Python are you using ?