numpy f2py question

sturlamolden sturlamolden at
Sat Oct 3 01:14:41 CEST 2009

On 2 Okt, 22:41, George Trojan <george.tro... at> wrote:
> I have a problem with numpy's vectorize class and f2py wrapped old
> FORTRAN code. I found that the function _get_nargs() in
> site-packages/numpy/lib/ tries to find the number of
> arguments for a function from an error message generated when the
> function is invoked with no arguments. However, with numpy 1.3.0 the
> error message is different that the code expects. Is there any known
> solution? I don';t know where the message is coming from, a cursory
> check of numpy files did not yield any hits. A ctypes issue?
> I did find an  unanswered seven weeks old related posting
> though I don't think this is gfortran related. Mine is 4.1.2.

The wrappers generated by f2py just calls PyArg_ParseTupleAndKeywords
and return NULL if it fails. The error message from
PyArg_ParseTupleAndKeywords does not fit the regex used by _get_nargs:

re.compile(r'.*? takes exactly (?P<exargs>\d+) argument(s|) \((?
P<gargs>\d+) given\)')

It should have said

re.compile(r'.*? takes (exactly|at least) (?P<exargs>\d+) argument(s|)
\((?P<gargs>\d+) given\)')

It is not just an f2py issue. It affects any function that uses
keyword arguments. I'll file this as a bug on NumPy trac.


More information about the Python-list mailing list