Pandas version checks

  • [X] I have checked that this issue has not already been reported.

  • [X] 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
import numpy as np

cat = pd.CategoricalDtype(["A", "B"])
test = pd.concat([pd.Series(["A", "B", "A"], dtype=cat), pd.Series([1, 2, 3], dtype=float)], axis=1)
select = np.array([True, True, True])
test.loc[select, 0] = test.loc[select, 0]
test.loc[select, 1] = test.loc[select, 1]

Issue Description

In the above example, "test.loc[select, 0] = test.loc[select, 0]" will output a warning, whereas "test.loc[select, 1] = test.loc[select, 1]" does not. This behaviour only occurs if the DataFrame has two or more columns and if one has a categorical dtype.

Expected Behavior

I would expect that no warning is printed, when "test.loc[select, 0] = test.loc[select, 0]" is executed.

Installed Versions

INSTALLED VERSIONS ------------------ commit : 2e218d10984e9919f0296931d92ea851c6a6faf5 python : 3.9.13.final.0 python-bits : 64 OS : Windows OS-release : 10 Version : 10.0.19044 machine : AMD64 processor : Intel64 Family 6 Model 140 Stepping 1, GenuineIntel byteorder : little LC_ALL : None LANG : en LOCALE : de_DE.cp1252 pandas : 1.5.3 numpy : 1.22.4 pytz : 2022.7.1 dateutil : 2.8.2 setuptools : 67.2.0 pip : 22.3.1 Cython : 0.29.33 pytest : 7.2.1 hypothesis : None sphinx : 4.5.0 blosc : None feather : None xlsxwriter : None lxml.etree : 4.9.2 html5lib : 1.1 pymysql : None psycopg2 : None jinja2 : 3.1.2 IPython : 7.34.0 pandas_datareader: None bs4 : 4.11.2 bottleneck : None brotli : None fastparquet : None fsspec : 2022.11.0 gcsfs : None matplotlib : 3.6.3 numba : 0.55.2 numexpr : 2.8.4 odfpy : None openpyxl : 3.1.0 pandas_gbq : None pyarrow : 10.0.1 pyreadstat : None pyxlsb : None s3fs : None scipy : 1.10.0 snappy : None sqlalchemy : None tables : 3.8.0 tabulate : 0.8.10 xarray : None xlrd : 2.0.1 xlwt : None zstandard : None tzdata : 2022.7

Comment From: phofl

Can you please post the warning? There is no warning on main

Comment From: SergejKr

Here is the warning I get:

DeprecationWarning: In a future version, df.iloc[:, i] = newvals will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either df[df.columns[i]] = newvals or, if columns are non-unique, df.isetitem(i, newvals)

Comment From: phofl

This is expected, see the warning but removed in 2.0 because the behavior changed

Comment From: SergejKr

How is this warning expected on a category type but not on a float type?

I do only get the warning if executing "test.loc[select, 0] = test.loc[select, 0]", i.e., an operation on the category type Series is done. Executing "test.loc[select, 1] = test.loc[select, 1]" does not yield a warning.

I would expect that either both calls return a warning or None.