-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: Merge error when merge col is int64 and Int64 #46178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I duplicate reported this bug in #46799, with a couple other notes there. I confirmed that this is present on main. Also, a slightly more precise description of the conditions that create this bug are:
|
This was solved recently through mask support in merge operations |
Can you tell me how this was solved? I still have the same error. Trying to merge two dataframes on a column that is read as an Int64 and contains missing values. int() check fails on the NAType in the column. |
Bummer! Thanks for the report. What is If both columns are Int64, then this might be a different (but related) bug (see my condition above where dtypes must be different). Give us a reproducible example if you want us to investigate. |
Hey! I'm running into this too.
|
Can you provide a reproducer? |
I had a similar problem with Int32DType. Solved it by casting the column in
question to int.
Met vriendelijke groet / Kind regards
René Flohil (hij/hem)
…On Fri, 23 Jun 2023, 16:26 Charles Fauman, ***@***.***> wrote:
Hey! I'm running into this too.
In my case, I get the error merging a float field with an int64dtype field
>>> import pandas as pd
>>> pd.__version__
'2.0.2'
>>> pd.merge(pd.DataFrame([1.0]), pd.DataFrame([1.0]).astype(pd.Int64Dtype()))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "E:\workspace\CottonEye\venv\lib\site-packages\pandas\core\reshape\merge.py", line 148, in merge
op = _MergeOperation(
File "E:\workspace\CottonEye\venv\lib\site-packages\pandas\core\reshape\merge.py", line 741, in __init__
self._maybe_coerce_merge_keys()
File "E:\workspace\CottonEye\venv\lib\site-packages\pandas\core\reshape\merge.py", line 1333, in _maybe_coerce_merge_keys
casted = lk.astype(rk.dtype) # type: ignore[arg-type]
TypeError: Cannot interpret 'Int64Dtype()' as a data type
—
Reply to this email directly, view it on GitHub
<#46178 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AB7QAL75GRW3TWNCEJS2BNLXMWRSFANCNFSM5PQTZTAA>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
Where you able to solve it? |
Sorry folks, this is fixed now and will be in 2.1 |
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
Merging two DataFrames on a column (
col1
) that isInt64
in the first andint64
in the second DF, causes the following confusing error message:Expected Behavior
If the types of the "merge columns" are compatible, the merge should complete with no errors. Or, alternatively, the error message should warn the user of a type mismatch and of the need of casting one of the columns.
For example, casting the
col1
indf2
fromint64
toInt64
will result in the correct merge:However, this workaround looks a bit too convoluted for me.
Installed Versions
1.4.1
The text was updated successfully, but these errors were encountered: