When merging on boolean index in right dataframe, merge key becomes an object #23884
Labels
Bug
Dtype Conversions
Unexpected or buggy dtype conversions
Reshaping
Concat, Merge/Join, Stack/Unstack, Explode
Code Sample, a copy-pastable example if possible
Output:
Problem description
I have a dataframe with which has a column of type
bool
, and another dataframe where the index is of typebool
. When I merge the first dataframe with the second, the column is promoted to an object, rather than maintaining its boolean type. This causes issues because the ~ operator then no longer inverts true and false; I have to manually convert the column back to a boolean. I'm guessing this is because there's not a BooleanIndex type in Pandas, so the index type is object. But it's quite confusing when columns unexpectedly change types during a merge.The boolean index is part of a MultiIndex in my actual project, but the issue occurs even with a single index as shown in the MWE above.
Expected Output
column
b
should remain a boolean.Output of
pd.show_versions()
The text was updated successfully, but these errors were encountered: