[Numpy-discussion] the mean, var, std of non-arrays

Skipper Seabold jsseabold at gmail.com
Thu Jul 18 23:18:49 EDT 2013


On Thu, Jul 18, 2013 at 10:49 PM, Yaroslav Halchenko
<lists at onerussian.com>wrote:

> Hi everyone,
>
> Some of my elderly code stopped working upon upgrades of numpy and
> upcoming pandas: https://github.com/pydata/pandas/issues/4290 so I have
> looked at the code of
>
>   2481   def mean(a, axis=None, dtype=None, out=None, keepdims=False):
>   2482       """
>   ...
>   2489       Parameters
>   2490       ----------
>   2491       a : array_like
>   2492           Array containing numbers whose mean is desired. If `a` is
> not an
>   2493           array, a conversion is attempted.
>   ...
>   2555       """
>   2556       if type(a) is not mu.ndarray:
>   2557           try:
>   2558               mean = a.mean
>   2559               return mean(axis=axis, dtype=dtype, out=out)
>   2560           except AttributeError:
>   2561               pass
>   2562
>   2563       return _methods._mean(a, axis=axis, dtype=dtype,
>   2564                               out=out, keepdims=keepdims)
>
> here 'array_like'ness is checked by a having mean function.  Then it is
> assumed
> that it has the same definition as ndarray, including dtype keyword
> argument.
>
> Not sure anyways if my direct numpy.mean application to pandas DataFrame is
> "kosher" -- initially I just assumed that any argument is asanyarray'ed
> first
> -- but I think here catching TypeError for those incompatible .mean's
> would not
> hurt either.  What do you think?  Similar logic applies to mean cousins
> (var,
> std, ...?) decorated around _methods implementations.


Related? From a while ago.

https://github.com/numpy/numpy/pull/160

Skipper
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20130718/49d86596/attachment.html>


More information about the NumPy-Discussion mailing list