[SciPy-dev] stats confusion

josef.pktd@gmai... josef.pktd@gmai...
Wed Jun 17 07:59:38 CDT 2009


On Wed, Jun 17, 2009 at 8:23 AM, Neal Becker<ndbecker2@gmail.com> wrote:
> I'm still finding stats usage confusing.  The doc
> (http://docs.scipy.org:80/doc/scipy/reference/generated/scipy.stats.chi2.html?highlight=chi2#scipy.stats.chi2)
>
> says:
>
> chi2.cdf(x,df,loc=0,scale=1) :
>
> And even has an example:
> prb = chi2.cdf(x,df)
>
> But if df is given as keyword:
>  scipy.stats.chi2.cdf(1, df=2)
> ERROR: An unexpected error occurred while tokenizing input
> The following traceback may be corrupted or invalid
> The error message is: ('EOF in multi-line statement', (1331, 0))
>
> ---------------------------------------------------------------------------
> TypeError                                 Traceback (most recent call last)
>
> /home/nbecker/globalstar/<ipython console> in <module>()
>
> /usr/lib64/python2.6/site-packages/scipy/stats/distributions.pyc in
> cdf(self, x, *args, **kwds)
>    623         if any(cond):  #call only if at least 1 entry
>    624             goodargs = argsreduce(cond, *((x,)+args))
> --> 625             place(output,cond,self._cdf(*goodargs))
>    626         if output.ndim == 0:
>    627             return output[()]
>
> TypeError: _cdf() takes exactly 3 arguments (2 given)
>
> What's going on here?  Do stats not accept keyword args as per normal python
> usage?
>

As the signature indicates df is a positional argument and not a
keyword argument

>>> scipy.stats.chi2.cdf(1, 2)
0.39346934028736652

Because the generic functions have *args *kwds, df as keyword gets
swallowed (instead of raising a TypeError) and _cdf has one argument
too few.

Josef


More information about the Scipy-dev mailing list