Description
-
I have checked that this issue has not already been reported.
-
I have confirmed this bug exists on the latest version of pandas.
-
(optional) I have confirmed this bug exists on the master branch of pandas.
Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.
Code Sample, a copy-pastable example
import pandas as pd
df1 = pd.DataFrame([(1, pd.Timestamp.utcfromtimestamp(1))] * 5, columns=['nb', 'ts'])
df2 = pd.DataFrame([(2, pd.Timestamp.utcfromtimestamp(2))] * 3, columns=['nb', 'ts'])
print("df2:\n", df2)
print("\ndf1 before:\n", df1)
df1.iloc[[1, 4]] = df2.iloc[[0, 2]].values
print("\ndf1 after replacing some rows by some of df2's rows:\n", df1)
Full output is
df2:
nb ts
0 2 1970-01-01 00:00:02
1 2 1970-01-01 00:00:02
2 2 1970-01-01 00:00:02
df1 before:
nb ts
0 1 1970-01-01 00:00:01
1 1 1970-01-01 00:00:01
2 1 1970-01-01 00:00:01
3 1 1970-01-01 00:00:01
4 1 1970-01-01 00:00:01
df1 after replacing some rows by some of df2's rows:
nb ts
0 1 1000000000
1 2 1970-01-01 00:00:02
2 1 1000000000
3 1 1000000000
4 2 1970-01-01 00:00:02
Problem description
The rows which are not overwritten have their dtype changed (cast from Timestamp to int) although all dtypes align.
Expected Output
df1 after replacing some rows by some of df2's rows:
nb ts
0 1 1970-01-01 00:00:01
1 2 1970-01-01 00:00:02
2 1 1970-01-01 00:00:01
3 1 1970-01-01 00:00:01
4 2 1970-01-01 00:00:02
Output of pd.show_versions()
INSTALLED VERSIONS
commit : None
python : 3.6.7.final.0
python-bits : 64
OS : Linux
OS-release : 3.10.0-862.14.4.el7.x86_64
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : en_US.UTF-8
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
pandas : 1.0.3
numpy : 1.14.5
pytz : 2019.2
dateutil : 2.8.0
pip : 19.2.1
setuptools : 39.1.0
Cython : 0.29.13
pytest : 5.0.1
hypothesis : None
sphinx : 2.1.2
blosc : None
feather : None
xlsxwriter : 1.1.8
lxml.etree : 4.4.0
html5lib : 1.0.1
pymysql : None
psycopg2 : None
jinja2 : 2.10.1
IPython : 7.13.0
pandas_datareader: None
bs4 : 4.8.0
bottleneck : 1.2.1
fastparquet : None
gcsfs : None
lxml.etree : 4.4.0
matplotlib : 3.1.1
numexpr : 2.6.9
odfpy : None
openpyxl : 2.6.2
pandas_gbq : None
pyarrow : None
pytables : None
pytest : 5.0.1
pyxlsb : None
s3fs : None
scipy : 1.3.0
sqlalchemy : 1.3.6
tables : 3.5.2
tabulate : 0.8.3
xarray : None
xlrd : 1.2.0
xlwt : 1.3.0
xlsxwriter : 1.1.8
numba : 0.45.1