Pandas: add offset to date when DST changes

Viewed 237

I'm not sure if this is a pandas bug or if I'm doing something wrong.

Given a datetime like this:

foo_date = pd.Timestamp('2016-10-30 00:00:00', 
                        tz=pytz.timezone('Europe/Helsinki'))

And an interval offset ('D', '10m', whatever), I want to get the start date of the next interval.

I do it this way:

offset = pd.tseries.frequencies.to_offset('D') # 'D' or any other offset, it shouldn't matter
new_date = foo_date + offset

Or like this (same result):

offset = pd.DateOffset(1)
new_date = foo_date + offset

I'm expecting this:

Timestamp('2016-10-31 00:00:00+0200', tz='Europe/Helsinki')  

But instead, I'm getting this:

Timestamp('2016-10-30 23:00:00+0200', tz='Europe/Helsinki')   

The problem is that 2016-10-30 is a 25 hours day, due to the DST change, so when I add offset, it only adds 24 hours and I'm getting the wrong datetime.

I think time offset should be timezone-aware, but it seems they're not. How can I achieve what I need?

0 Answers
Related