Pandas: Appending a row of boolean values to df using `loc` changes to `int`
Why is it not automatically changing the dtypes of columns to object when I append boolean to it?
Because the type are being upcasted (see upcasting), from the documentation:
Types can potentially be upcasted when combined with other types, meaning they are promoted from the current type (e.g. int to float).
Upcasting works according to numpy rules:
Upcasting is always according to the numpy rules. If two different dtypes are involved in an operation, then the more general one will be used as the result of the operation.
To understand how the numpy rules are applied you can use the function find_common_type, as below:
res = np.find_common_type([bool, np.bool], [np.int32, np.int64]) print(res)