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
import pandas as pd
df = pd.DataFrame()
condition = [True, False, True, True]
for i in range(len(condition)):
df.at[i,'truth'] = condition[i]
Issue Description
While making a column from a loop, I get an incompaitible dtype warning.
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. df.at[i,'truth'] = condition[i]
Pandas most probably complaints about casting to float64
because np.NaN
is considered a float and pandas defaults to making a column filled with np.NaN
Expected Behavior
No warning
Installed Versions
Comment From: yuanx749
Note that there is no warning in the current version. Seems it has been fixed after 2.1.