I searched online but found nothing on the problem I'm facing.
It seems that pandas.DataFrame operations on index with timezone-aware dates is order of magnitude slower than on regular datetimes.
here are the ipython timings.
first with standard datetimes :
import pandas as pd
import numpy as np
dates=pd.date_range('2010/01/01 00:00:00', '2010/12/31 00:00:00', freq='1T')
DF=pd.DataFrame(data=np.random.rand(len(dates)), index=dates, columns=["value"])
# compute timedeltas between dates
%timeit DF["temp"] = DF.index
%timeit DF["deltas"] = (DF["temp"] - DF["temp"].shift())
results are :
1000 loops, best of 3: 1.13 ms per loop
100 loops, best of 3: 17.1 ms per loop
so far, so good.
now just adding timezone information :
import pandas as pd
import numpy as np
dates=pd.date_range('2010/01/01 00:00:00', '2010/12/31 00:00:00', freq='1T')
# NEW: filter dates to avoid DST problems
dates=dates[dates.hour>2] # to avoid AmbiguousInferError or NonExistentDateError
DF=pd.DataFrame(data=np.random.rand(len(dates)), index=dates, columns=["value"])
# NEW: add timezone info
DF.index = DF.index.tz_localize(tz="America/New_York", ambiguous="infer")
# compute timedeltas between dates
%timeit DF["temp"] = DF.index
%timeit DF["deltas"] = (DF["temp"] - DF["temp"].shift())
and now, results are :
1 loops, best of 3: 5.43 s per loop
1 loops, best of 3: 16 s per loop
why is that ??
I really don't understand where is the bottleneck here...
for info (from conda list) :
anaconda 2.2.0 np19py34_0
conda 3.12.0 py34_0
numpy 1.9.2 py34_0
pandas 0.16.1 np19py34_0
pytz 2015.4 py34_0
scipy 0.15.1 np19py34_0