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. -- Yaroslav O. Halchenko, Ph.D. http://neuro.debian.net http://www.pymvpa.org http://www.fail2ban.org Senior Research Associate, Psychological and Brain Sciences Dept. Dartmouth College, 419 Moore Hall, Hinman Box 6207, Hanover, NH 03755 Phone: +1 (603) 646-9834 Fax: +1 (603) 646-1419 WWW: http://www.linkedin.com/in/yarik
On Thu, Jul 18, 2013 at 10:49 PM, Yaroslav Halchenko <lists@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
On Thu, 18 Jul 2013, Skipper Seabold wrote:
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. [3]https://github.com/numpy/numpy/pull/160
yeah... That is how I thought "it is working", but I guess it was left without asanyarraying for additional flexibility/performance so any array-like object could be used, not just ndarray derived classes. -- Yaroslav O. Halchenko, Ph.D. http://neuro.debian.net http://www.pymvpa.org http://www.fail2ban.org Senior Research Associate, Psychological and Brain Sciences Dept. Dartmouth College, 419 Moore Hall, Hinman Box 6207, Hanover, NH 03755 Phone: +1 (603) 646-9834 Fax: +1 (603) 646-1419 WWW: http://www.linkedin.com/in/yarik
On Thu, Jul 18, 2013 at 9:24 PM, Yaroslav Halchenko <lists@onerussian.com>wrote:
On Thu, 18 Jul 2013, Skipper Seabold wrote:
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. [3]https://github.com/numpy/numpy/pull/160
yeah... That is how I thought "it is working", but I guess it was left without asanyarraying for additional flexibility/performance so any array-like object could be used, not just ndarray derived classes.
Speaking of which, there is a PR for nan{mean, var, std)<https://github.com/numpy/numpy/pull/3534> that you might want to check before it gets committed. There might be some modifications that you would want to add. Chuck
On Thu, 18 Jul 2013, Charles R Harris wrote:
yeah... That is how I thought "it is working", but I guess it was left without asanyarraying for additional flexibility/performance so any array-like object could be used, not just ndarray derived classes.
Speaking of which, there is a PR for [3]nan{mean, var, std) that you might want to check before it gets committed. There might be some modifications that you would want to add.
well -- the only modifications to non-nan mean was a docstring's see also. there though input is explicitly converted/copied to ndarray so no custom .mean() functions would be called, thus issue a bit orthogonal as far as I see -- Yaroslav O. Halchenko, Ph.D. http://neuro.debian.net http://www.pymvpa.org http://www.fail2ban.org Senior Research Associate, Psychological and Brain Sciences Dept. Dartmouth College, 419 Moore Hall, Hinman Box 6207, Hanover, NH 03755 Phone: +1 (603) 646-9834 Fax: +1 (603) 646-1419 WWW: http://www.linkedin.com/in/yarik
participants (3)
-
Charles R Harris -
Skipper Seabold -
Yaroslav Halchenko