[Numpy-discussion] Bug in numpy std, etc. with other data structures?
Sat Sep 17 21:50:56 CDT 2011
On Sat, Sep 17, 2011 at 4:12 PM, Wes McKinney <firstname.lastname@example.org> wrote:
> On Sat, Sep 17, 2011 at 4:48 PM, Skipper Seabold <email@example.com> wrote:
>> Just ran into this. Any objections for having numpy.std and other
>> functions in core/fromnumeric.py call asanyarray before trying to use
>> the array's method? Other data structures like pandas and larry define
>> their own std method, for instance, and this doesn't allow them to
>> pass through. I'm inclined to say that the issue is with numpy, though
>> maybe the data structures shouldn't shadow numpy array methods while
>> altering the signature. I dunno.
>> df = pandas.DataFrame(np.random.random((10,5)))
>> TypeError: std() got an unexpected keyword argument 'dtype'
>> array([ 0.30883352, 0.3133324 , 0.26517361, 0.26389029, 0.20022444])
>> Though I don't think this would work with larry yet.
>> Pull request: https://github.com/numpy/numpy/pull/160
>> NumPy-Discussion mailing list
numpy.std() does accepts array-like which obvious means that
np.std([1,2,3,5]) works making asanyarray call a total waste of cpu
time. Clearly pandas is not array-like input (as Wes points out below)
so an error is correct. Doing this type of 'fix' will have unintended
consequences when other non-numpy objects are incorrectly passed to
numpy functions. Rather you should determine why 'array-like' failed
here IF you think a pandas object is either array-like or a numpy
> Note I've no real intention of making DataFrame fully ndarray-like--
> but it's nice to be able to type:
> etc. which works the same as ndarray. I suppose the
> __array__/__array_wrap__ interface is there largely as a convenience.
> NumPy-Discussion mailing list
I consider that the only way pandas or any other numpy-derivative to
overcome this is get into numpy/scipy. After all Travis opened the
discussion for Numpy 3 which you could still address.
PS Good luck on the ddof thing given the past discussions on it!
More information about the NumPy-Discussion