Look at the example:
In [1]: import pandas.tseries.offsets as ofs
In [2]: ofs.Minute(1) + ofs.Second(1)
Out[2]: <61 * Seconds>
In [3]: ofs.Second(0)
Out[3]: <0 * Seconds>
In [4]: ofs.Minute(1) + ofs.Second(0)
Out[4]: <Minute>
In [5]: 0*ofs.Second(1)
Out[5]: <0 * Seconds>
In [6]: ofs.Minute(1) + 0*ofs.Second(1)
Out[6]: <Minute>
In [7]: ofs.Minute(1) + ofs.Second(1) - ofs.Second(1)
Out[7]: <60 * Seconds>
As you can see, the result of adding a zero offset is in Minutes while adding a Second and then substract it is in Seconds.
Why is it different? Is the substraction trick reliable?
ofs.Minute(1) + ofs.Second(1) returns a second ofs string representation.
then you use that second ofs and substract another second ofs which will normally return a second ofs string representation
as an example doing this would return second because you don't change the minute ofst string representation first:
ofs.Minute(1) + ofs.Second(1) - ofs.Second(1)
Out[35]: <60 * Seconds>
ofs.Minute(1) + (ofs.Second(1) - ofs.Second(1))
Out[36]: <Minute>
As far as I've been taught, there are 60 seconds in 1 minute
(ofs.Second(1) - ofs.Second(1)) == ofs.Second(0)
True
I'd say, yes! It's reliable.
Also, notice
ofs.Minute(1) + (ofs.Second(1) - ofs.Second(1))
<Minute>
Then string representation choice is not associative.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With