Code Sample, a copy-pastable example if possible
df = pd.DataFrame({
'dates_1' : pd.date_range(start='2015-01-01', periods=5),
'dates_2' : pd.date_range(start='2016-01-01', periods=5)
})
df.dates_2 - df.dates_1
df_2 = df.drop(df.index)
df_2.dates_2 - df_2.dates_1
Problem description
Subtracting two empty Series with dtypes of datetime64[ns] causes a TypeError to be thrown.
Expected Output
Would expect the subtraction to return an empty series of timedelta64[ns]. i.e, Series([], dtype: timedelta64[ns])
Output of pd.show_versions()
INSTALLED VERSIONS
------------------
commit: None
python: 3.5.2.final.0
python-bits: 64
OS: Windows
OS-release: 7
machine: AMD64
processor: Intel64 Family 6 Model 45 Stepping 7, GenuineIntel
byteorder: little
LC_ALL: None
LANG: None
pandas: 0.18.1
nose: 1.3.7
pip: 9.0.1
setuptools: 27.2.0
Cython: 0.25.1
numpy: 1.11.1
scipy: 0.18.0
statsmodels: 0.6.1
xarray: None
IPython: 5.1.0
sphinx: 1.4.1
patsy: 0.4.1
dateutil: 2.5.3
pytz: 2016.6.1
blosc: None
bottleneck: None
tables: 3.2.2
numexpr: 2.6.1
matplotlib: 1.5.1
openpyxl: None
xlrd: 1.0.0
xlwt: 1.1.2
xlsxwriter: 0.9.2
lxml: None
bs4: 4.5.1
html5lib: None
httplib2: None
apiclient: None
sqlalchemy: 1.0.13
pymysql: None
psycopg2: None
jinja2: 2.8
boto: 2.42.0
pandas_datareader: None
Comment From: jreback
has been fixed in more recent versions (maybe this https://github.com/pandas-dev/pandas/commit/d8cd33b148daba78f1450c19c69cfe4896cfb98c) fixed.
In [1]: df = pd.DataFrame({
...: 'dates_1' : pd.date_range(start='2015-01-01', periods=5),
...: 'dates_2' : pd.date_range(start='2016-01-01', periods=5)
...: })
...:
...: df.dates_2 - df.dates_1
...: df_2 = df.drop(df.index)
...: df_2.dates_2 - df_2.dates_1
...:
Out[1]: Series([], dtype: timedelta64[ns])
In [2]: pd.__version__
Out[2]: '0.19.2'