[Numpy-discussion] Bug in numpy std, etc. with other data structures?
josef.pktd at gmail.com
josef.pktd at gmail.com
Sat Sep 17 20:36:32 EDT 2011
On Sat, Sep 17, 2011 at 5:12 PM, Wes McKinney <wesmckinn at gmail.com> wrote:
> On Sat, Sep 17, 2011 at 4:48 PM, Skipper Seabold <jsseabold at gmail.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)))
>>
>> np.std(df,axis=0)
>> <snip>
>> TypeError: std() got an unexpected keyword argument 'dtype'
>>
>> np.std(np.asanyarray(df),axis=0)
>> 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
>>
>> Skipper
>> _______________________________________________
>> NumPy-Discussion mailing list
>> NumPy-Discussion at scipy.org
>> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>>
>
> Note I've no real intention of making DataFrame fully ndarray-like--
> but it's nice to be able to type:
>
> df.std(axis=0)
> df.std(axis=1)
> np.sqrt(df)
>
> etc. which works the same as ndarray. I suppose the
> __array__/__array_wrap__ interface is there largely as a convenience.
I'm a bit worried about the different ddof defaults in cases like
this. Essentially we will not be able to rely on ddof=0 anymore.
Different defaults on axis are easy to catch, but having the same
function call return sometimes ddof=0 and sometimes ddof=1 might make
for some fun debugging.
Josef
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
More information about the NumPy-Discussion
mailing list