pandas.datetime addition: What's wrong?

Paulo da Silva p_s_d_a_s_i_l_v_a_ns at netcabo.pt
Wed Jun 8 01:18:18 EDT 2016


Às 04:08 de 08-06-2016, MRAB escreveu:
> On 2016-06-08 03:09, Paulo da Silva wrote:
>> Hi all!
>>
...
>>
>> More generally I have a class derived from pandas.datetime and I want to
>> implement its own __add__ that at a given point call super __add__.
>>
>> For example:
>>
>> class C(pandas.datetime):
>>     ...
>>     def __add__(self,n):
>>         ...
>>         r=super(C,self).__add__(pd.DateOffset(days=n))
>>         ...
>> BTW, in the last line is it needed and how to "cast" self to
>> pandas.datetime?
>>
...

> When you have x+y, it tries x.__add__(y). If that fails, it then tries
> y.__radd__(x).
That's it!
> 
> Does that mean that the calculation above is actually implemented by the
> DateOffset class?
It seems so. Using __radd__ it works.
> 
> Does pd.to_datetime return a datetime instance?
Yes.
> 
I still have the problem of self being C (not pandas.datetime).
I tried self.__class__=pandas.datetime but it says
something like "__class__ assignment: only for heap types"
I don't know what this means.

Using a new object op=pandas.datetime(self.year,self.month,self.day)
works but it's too heavy :-)

Thank you very much.




More information about the Python-list mailing list