Description
xref #6942
xref #12499
xref #14179
Simple repro, casting to object
, but a datetimelike is cast to its underlying repr
In [1]: s = pd.Series([1])
In [2]: s
Out[2]:
0 1
dtype: int64
In [3]: s[1] = pd.Timestamp('20130101')
In [4]: s
Out[4]:
0 1
1 1356998400000000000
dtype: object
Code Sample, a copy-pastable example if possible
>>> import pandas as pd
>>> s = pd.Series()
>>> s.loc['date'] = pd.Timestamp.now()
>>> s
date 2017-02-27 15:04:32.357
dtype: datetime64[ns]
>>> s.loc['date2'] = pd.Timestamp.now()
>>> s
date 2017-02-27 15:04:32.357
date2 2017-02-27 15:04:41.724
dtype: datetime64[ns]
>>> s.loc['date3'] = 3
>>> s
date 2017-02-27 15:04:32.357000
date2 2017-02-27 15:04:41.724000
date3 3
dtype: object
>>> s.loc['date4'] = pd.Timestamp.now()
>>> s
date 2017-02-27 15:04:32.357000
date2 2017-02-27 15:04:41.724000
date3 3
date4 1488207907032000000
dtype: object
Problem description
When a series' dtype is object, .loc assignment of pd.Timestamp values results in being cast to a long, rather than remaining a datetime. Since the dtype is object, I would expect objects to be uncasted.
Expected Output
The expected behavior is to not be casted, i.e. to remain a datetime.
>>> s = s.append(pd.Series(data = [pd.Timestamp.now()], index = ['date_x']))
>>> s
date 2017-02-27 15:04:32.357000
date2 2017-02-27 15:04:41.724000
date3 3
date4 1488207907032000000
date_x 2017-02-27 15:11:03.995000
dtype: object
Output of pd.show_versions()
INSTALLED VERSIONS
commit: None
python: 2.7.12.final.0
python-bits: 64
OS: Windows
OS-release: 10
machine: AMD64
processor: Intel64 Family 6 Model 60 Stepping 3, GenuineIntel
byteorder: little
LC_ALL: None
LANG: None
LOCALE: None.None
pandas: 0.19.2
nose: 1.3.7
pip: 9.0.1
setuptools: 33.1.0.post20170122
Cython: 0.25.2
numpy: 1.10.4
scipy: 0.17.1
statsmodels: 0.8.0
xarray: 0.9.1
IPython: 5.2.2
sphinx: 1.5.2
patsy: 0.4.1
dateutil: 2.6.0
pytz: 2016.10
blosc: None
bottleneck: 1.2.0
tables: 3.3.0
numexpr: 2.6.1
matplotlib: 2.0.0
openpyxl: 2.4.1
xlrd: 1.0.0
xlwt: 1.2.0
xlsxwriter: 0.9.6
lxml: 3.7.2
bs4: 4.5.3
html5lib: 0.999
httplib2: None
apiclient: None
sqlalchemy: 1.1.5
pymysql: None
psycopg2: None
jinja2: 2.8
boto: 2.45.0
pandas_datareader: 0.2.1