[Numpy-discussion] Keywords in wrapped functions

Robert Kern robert.kern at gmail.com
Tue Jun 24 14:11:12 EDT 2008


On Tue, Jun 24, 2008 at 13:03, Pierre GM <pgmdevlist at gmail.com> wrote:
> All,
> Sorry to bumpt the post, accept my apologies for my rudeness, but I'm
> curious...
> So, let me rephrase my question:
>
> Many numpy functions (min, max, sum...) based on ndarray methods have a
> construction of the style
> #-----------------------------------------------
> def amin(a, axis=None, out=None):
>    try:
>        amin = a.min
>    except AttributeError:
>        return _wrapit(a, 'min', axis, out)
>    return amin(axis, out)
> #-----------------------------------------------
>
> I'm wondering why the initial keywords arguments are transformed into
> positional arguments in the return. In the previous example, I would expect a
> line like
> return amin(axis=axis, out=out)
>
> [Actually, I would even prefer a
> return amin(axis=axis, out=out, **other_optional_parameters), which would
> permit to add some extra parameters such as a "fill_value", when dealing with
> masked arrays ?]
>
> Is this for efficiency purposes ?

Most likely, the author just didn't realize that it might matter. Go
ahead with your changes.

-- 
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



More information about the NumPy-Discussion mailing list