[SciPy-dev] stats confusion

David Goldsmith d_l_goldsmith at yahoo.com
Wed Jun 17 17:08:40 EDT 2009


OK, this is where I chime in: should the doc be clarified, or does this seem like enough of an arcane deviation from "naive" Python practice that we'll actually want to modify the code (and thus postpone modifying the doc 'til that's done)?

DG

--- On Wed, 6/17/09, josef.pktd at gmail.com <josef.pktd at gmail.com> wrote:

> From: josef.pktd at gmail.com <josef.pktd at gmail.com>
> Subject: Re: [SciPy-dev] stats confusion
> To: "SciPy Developers List" <scipy-dev at scipy.org>
> Date: Wednesday, June 17, 2009, 7:20 AM
> On Wed, Jun 17, 2009 at 9:43 AM,
> Pauli Virtanen<pav at iki.fi> wrote:
> > Wed, 17 Jun 2009 09:37:10 -0400, josef.pktd
> kirjoitti:
> > [clip]
> >> Positional arguments cannot be called as keyword
> arguments, that is
> >> standard python.
> >> (on the other hand keyword arguments can be called
> also as positional
> >> arguments.
> >
> > Positional arguments can usually be called as keyword
> arguments in
> > standard Python.
> >
> > def foo(a):
> >    print a
> >
> > foo(a=5)
> >
> >> the signature and help has standard notation:
> >>
> >> eg. signature:  np.maximum(x1, x2[, out])
> >>
> >>>>> np.maximum(x1=[5], x2=[6])
> >> Traceback (most recent call last):
> >> TypeError: 'x2' is an invalid keyword to maximum
> >
> > The only exception are functions provided by C
> extension modules, and
> > functions that use *args.
> >
> 
> Thanks, I didn't know this is possible.
> 
> I found the explanation in the Python Reference Manual. But
> I don't
> thinks I have ever seen it used. And it looks a bit fragile
> to me if
> you want to refactor the argument list later by adding
> *args), and I
> get easily TypeErrors when mixing positional and keyword
> arguments if
> they are in the wrong sequence.
> So, I don't see any gain using positional arguments as
> keywords.
> 
> The problem in this example is that the the generic
> function cdf uses
> *args, **kwds, and checks the arguments and does the
> broadcasting
> before dispatching to the private method _cdf.
> 
> Calling the private method actually works with keywords
> >>> scipy.stats.chi2._cdf(1, df=2)
> 0.39346934028736652
> >>> scipy.stats.chi2._cdf(x=1, df=2)
> 0.39346934028736652
> 
> 
> I forgot to mention earlier: The generated docs are a merge
> between
> generic and distribution specific docstrings. I never
> checked whether
> this merge is completely correct in all cases.
> 
> Josef
> 
> > --
> > Pauli Virtanen
> _______________________________________________
> Scipy-dev mailing list
> Scipy-dev at scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-dev
> 


      



More information about the SciPy-Dev mailing list