Timestamp subtraction of NaT with timezones · Issue #11718 · pandas-dev/pandas (original) (raw)

In pandas 0.17.1, a TypeError is returned when trying to subtract a timezone-aware timestamp from a NaT timestamp:

In [1]: import pandas as pd

In [2]: pd.Timestamp(None, tz='utc') - pd.Timestamp('now', tz='utc') Traceback (most recent call last):

File "", line 1, in pd.Timestamp(None, tz='utc') - pd.Timestamp('now', tz='utc')

File "pandas\tslib.pyx", line 1099, in pandas.tslib._NaT.sub (pandas\tslib.c:21618)

File "pandas\tslib.pyx", line 1026, in pandas.tslib._Timestamp.sub (pandas\tslib.c:20036)

TypeError: Timestamp subtraction must have the same timezones or no timezones

Subtracting a timezone unaware timestamp from a NaT timestamp is no problem. Also subtracting a NaT from a timezone aware timestamp works:

In [3]: pd.Timestamp(None) - pd.Timestamp('now') Out[3]: NaT

In [4]: pd.Timestamp('now', tz='utc') - pd.Timestamp(None, tz='utc') Out[4]: NaT

In [5]: pd.Timestamp('now', tz='utc') - pd.Timestamp(None) Out[5]: NaT