package extension problem

Terry Reedy tjreedy at udel.edu
Mon Feb 13 14:12:44 EST 2012


On 2/13/2012 12:58 PM, Miki Tebeka wrote:
>> import new_pandas as np df =
>> np.DataFrame({'A':[1,2,3],'B':[4,5,6]}) col_A = df['A']
> I'm not familiar with pandas, but my *guess* will be that you'll need
> to override __getitem__ in the new DataFrame.

This is essentially the same problem that if you, for instance, subclass
int as myint, you need to override (wrap) *every* method to get them to 
return myints instead of ints.

class myint(int):
     ...
     def __add__(self, other): return myint(self+other)
     ....

In the OP's case, if the original class is in python, one might be able 
to just change the __class__ attribute. But I would make sure to have a 
good set of tests in any case.

-- 
Terry Jan Reedy




More information about the Python-list mailing list