You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have checked that this issue has not already been reported.
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
importpandasaspda=pd.DataFrame({"key": pd.Series([1, 2], dtype="int64")})
b=pd.DataFrame({"key": pd.Series([1.0, 2.0], dtype="float64")})
left_merge_dtypes=a.merge(b, on="key", how="left").dtypes# int64# Now we'll do a right merge with the arguments swappedright_merge_dtypes=b.merge(a, on="key", how="right").dtypes# float64print(left_merge_dtypes.equals(right_merge_dtypes))
# False
Issue Description
A "left" merge uses keys from the left frame, whereas a "right" merge uses keys from the right frame. If we also swap the order of the frame arguments to the merge, up to suffix naming, I expect that a.merge(b, how="left") <=> b.merge(a, how="right").
The result is the same, up to the dtype of the returned frames, which was surprising.
Expected Behavior
I would not expect different dtypes in these two cases. It looks like the merged key column is in this case taken from the "left" frame, ignoring how.
wence-
changed the title
BUG: left merge with mixed dtype key column has mismatching result dtypes compared to a "reversed" right merge
BUG: left merge where right frame has different dtype key column has mismatching result dtypes compared to a "reversed" right merge
Dec 11, 2023
Pandas version checks
I have checked that this issue has not already been reported.
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
Issue Description
A "left" merge uses keys from the left frame, whereas a "right" merge uses keys from the right frame. If we also swap the order of the frame arguments to the merge, up to suffix naming, I expect that
a.merge(b, how="left") <=> b.merge(a, how="right")
.The result is the same, up to the dtype of the returned frames, which was surprising.
Expected Behavior
I would not expect different dtypes in these two cases. It looks like the merged key column is in this case taken from the "left" frame, ignoring
how
.Installed Versions
The text was updated successfully, but these errors were encountered: