Description
Pandas version checks
-
I have checked that this issue has not already been reported.
-
I have confirmed this bug exists on the latest version of pandas.
-
I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
import pandas as pd
df1 = pd.DataFrame({"a": [1]})
df2 = pd.DataFrame({"d": [True]})
df1.loc[df2.index, df2.columns] = df2
Issue Description
The code above gives
FutureWarning: Setting an item of incompatible dtype is deprecated and will raise in a future error of pandas. Value '[ True]' has dtype incompatible with float64, please explicitly cast to a compatible dtype first. df1.loc[df2.index, df2.columns] = df
where I do not expect any warning at all. A new column is created without prior dtype defined.
Expected Behavior
No FutureWarning raised.
Installed Versions
INSTALLED VERSIONS
commit : a60ad39
python : 3.11.5.final.0
python-bits : 64
OS : Linux
OS-release : 5.15.0-87-generic
Version : #97~20.04.1-Ubuntu SMP Thu Oct 5 08:25:28 UTC 2023
machine : x86_64
processor :
byteorder : little
LC_ALL : None
LANG : C.UTF-8
LOCALE : en_US.UTF-8
pandas : 2.1.2
numpy : 1.26.0
pytz : 2023.3.post1
dateutil : 2.8.2
setuptools : 65.5.0
pip : 23.2.1
Cython : None
pytest : 7.4.2
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.1.2
IPython : None
pandas_datareader : None
bs4 : None
bottleneck : 1.3.7
dataframe-api-compat: None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : 3.8.0
numba : None
numexpr : 2.8.7
odfpy : None
openpyxl : 3.1.2
pandas_gbq : None
pyarrow : 13.0.0
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : 1.11.3
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
zstandard : None
tzdata : 2023.3
qtpy : None
pyqt5 : None