[SciPy-Dev] return named tuples

Warren Weckesser warren.weckesser at gmail.com
Sat Sep 6 15:10:03 EDT 2014


On Sat, Sep 6, 2014 at 12:54 PM, Clark Fitzgerald <clarkfitzg at gmail.com>
wrote:

> As a user, it would be convenient to access results by name. The relevant
> issue on Github is #3665 <https://github.com/scipy/scipy/issues/3665>.
> For example:
>
> summary = scipy.stats.describe(data)
>
> The current way to access the mean is to write `summary[2]`. It would be
> more clear to write `summary.mean`. I'd like to create a PR to implement
> this using namedtuples. Here is the idea:
>
> from collections import namedtuple
> from scipy.stats import describe, norm
>
>
> data = norm().rvs(100)
> unnamed = describe(data)
>
> output = namedtuple('describe', ('size', 'range', 'mean', 'variance',
>                                  'skewness', 'kurtosis'))
>
> named = output(*unnamed)
>
> This doesn't break backwards compatibility since:
>
> In [8]: unnamed[2] == named[2] == named.mean
> Out[8]: True
>
> This isn't limited to stats.describe; it would be beneficial anywhere that
> the return object is a tuple that's possibly unclear.
>
> The feedback on the Git issue has been positive. More feedback welcome.
>
>

Sounds good to me.  This could eventually be applied to many
functions in scipy.

Before adding this feature to a function, look for any related
functions that might return similar values.   We should try to
ensure that return values with the same meaning are consistently
given the same name.  We should avoid, for example, one statistical
test using "p", another using "pvalue" and third using "p_value".

We'll also need to update our docstring standard to include guidelines
for documenting such return values.

Warren



>
> Best,
> Clark Fitzgerald
> Statistics phd student, UC Davis
>
> _______________________________________________
> SciPy-Dev mailing list
> SciPy-Dev at scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/scipy-dev/attachments/20140906/fe43c5fa/attachment.html>


More information about the SciPy-Dev mailing list