Adding a couple milliseconds to datetime

fmt = '%Y-%m-%d %H:%M:%S %z'
datelist = ['2017-02-24 18:21:49 -0800', '2017-02-24 18:21:49 -0800', '2017-02-24 18:21:49 -0700']
dateseries = pd.Series(datelist)
tmptime = dateseries .apply(datetime.strptime, args=(fmt,))

since different time zones, tmptime won't be converted to dtype datetime64 and instead stay as datetime.datetime

addms = pd.Series([1, 2, 3])
addoffset = addms * timedelta(microseconds = 10000) # series of dtype timedelta64
tmptime + addoffset 
# TypeError: ufunc add cannot use operands with types dtype('O') and dtype('<m8[ns]')

Problem description

I want to add a couple milliseconds to a datetime object in pandas. The datatime object is not automatically converted into datetime64 when holding different time zones (and to_datetime() doesn't understand z in the fmt string). This creates the case where one pandas series is of type datetime while the time difference is of type timedelta64. Addition is not possible between these two types. It also does not seem possible to have pandas hold a timedelta (automatically converted to timedelta64). A workaround would be to add milliseconds in timedelta that is in a list (below)

Expected Output

addoffset2 = [i * timedelta(microseconds = 10000) for i in [1,2,3]] # list of type datetime.timedelta
tmptime + addoffset2

output

0    2017-02-24 18:21:49.010000-08:00
1    2017-02-24 18:21:49.020000-08:00
2    2017-02-24 18:21:49.030000-07:00
dtype: object

Output of pd.show_versions()

INSTALLED VERSIONS ------------------ commit: None python: 3.6.0.final.0 python-bits: 64 OS: Windows OS-release: 10 machine: AMD64 processor: Intel64 Family 6 Model 61 Stepping 4, GenuineIntel byteorder: little LC_ALL: None LANG: en_US.UTF-8 LOCALE: None.None pandas: 0.20.1 pytest: None pip: 9.0.1 setuptools: 27.2.0 Cython: None numpy: 1.12.1 scipy: None xarray: None IPython: None sphinx: None patsy: None dateutil: 2.6.0 pytz: 2017.2 blosc: None bottleneck: None tables: None numexpr: None feather: None matplotlib: None openpyxl: None xlrd: None xlwt: None xlsxwriter: None lxml: None bs4: None html5lib: None sqlalchemy: 1.1.9 pymysql: None psycopg2: 2.7.1 (dt dec pq3 ext lo64) jinja2: None s3fs: None pandas_gbq: None pandas_datareader: None

Comment From: jreback

Mixing timezones within a single Series is not performant and not supported. You are best off converting to a single timezone. (either UTC or a local) and simply adding.

In [40]: pd.to_datetime(datelist)
Out[40]: DatetimeIndex(['2017-02-25 02:21:49', '2017-02-25 02:21:49', '2017-02-25 01:21:49'], dtype='datetime64[ns]', freq=None)

In [41]: Series(pd.to_datetime(datelist).tz_localize('UTC').tz_convert('US/Pacific'))
Out[41]: 
0   2017-02-24 18:21:49-08:00
1   2017-02-24 18:21:49-08:00
2   2017-02-24 17:21:49-08:00
dtype: datetime64[ns, US/Pacific]

In [42]: Series(pd.to_datetime(datelist).tz_localize('UTC').tz_convert('US/Pacific')) + pd.to_timedelta([1, 2, 3], unit='ms')
Out[42]: 
0   2017-02-24 18:21:49.001000-08:00
1   2017-02-24 18:21:49.002000-08:00
2   2017-02-24 17:21:49.003000-08:00
dtype: datetime64[ns, US/Pacific]