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
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.