Open m0nzderr opened 9 months ago
This actually upcasts to object, which means that the warning is kind of correct, but this should definitely work and continue to work.
I suspect that we do a align under the hood that causes this, cc @MarcoGorelli
@phofl I'm not familiar with the implementation and have no idea about the reasons for the upcast, but, intuitively, I see no reason for that to happen. Both series already have the same dtype, so any conversion would be unnecessary. It is also very counter-intuitive to have different behaviors among primitive types (i.e., no upcast in case of ints or floats, but an upcast in case of bools...).
I think what's happening is that when we mask the series, we eventually try to set the items at the index array([1])
to array([False])
(which is the second element of data2). However, this array is an object type. When we try to cast this array to a bool, pandas gives a LossySetitemError, which may be the problem.
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.
[X] I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
Issue Description
The assignment
data1[condition] = data2[condition]
results in warning claiming incompatible types:data1[condition] = data2[condition]