numpy f2py question

George Trojan george.trojan at noaa.gov
Mon Oct 5 17:36:36 EDT 2009


sturlamolden wrote:
> On 2 Okt, 22:41, George Trojan <george.tro... at noaa.gov> 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/function_base.py 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 postinghttp://article.gmane.org/gmane.comp.python.numeric.general/32168/matc...
>> 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.
> 
> S.M.
> 
> 
> 
> 
> 
> 
That's not enough. f2py generated library ftest.so providing wrapper 
around Fortran function

integer function f2(a, b)
integer, intent(in) :: a, b

run from

try:
    ftest.f2()
except Exception, e:
    print e

produces traceback
Required argument 'a' (pos 1) not found
so the proposed fix will miss this case.

I tracked the issue to changes (from 2.5.2 to 2.6.2) of Python/getargs.c 
code. Still not sure what the proper fix should be.

George



More information about the Python-list mailing list