Skip to content

BUG: Compare returns wrong results for nullable int type #44014

Closed
@zazeng

Description

@zazeng

  • 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 master branch of pandas.

Reproducible Example

import pandas as pd

df1 = pd.DataFrame({'a': [4, 4, 4], 'b': [1, 2, 3]}).astype({'a': 'float64', 'b': 'float64'})

# Nullable int 'Int64' gives wrong results. 'int64' works just fine.
df2 = pd.DataFrame({'a': [1, 2, 3], 'b': [1, 2, 3]}).astype({'a': 'Int64', 'b': 'float64'})

df1.compare(df2, keep_shape=True)

Issue Description

The reproducible example returns

('a', 'self') ('a', 'other') ('b', 'self') ('b', 'other')
0 nan 1 nan nan
1 nan 2 nan nan
2 nan 3 nan nan

Expected Behavior

We expect the reproducible example to return

('a', 'self') ('a', 'other') ('b', 'self') ('b', 'other')
0 4 1 nan nan
1 4 2 nan nan
2 4 3 nan nan

Installed Versions

INSTALLED VERSIONS

commit : 73c6825
python : 3.8.10.final.0
python-bits : 64
OS : Linux
OS-release : 5.11.0-37-generic
Version : #41~20.04.2-Ubuntu SMP Fri Sep 24 09:06:38 UTC 2021
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_SG.UTF-8
LOCALE : en_SG.UTF-8

pandas : 1.3.3
numpy : 1.21.2
pytz : 2021.1
dateutil : 2.8.2
pip : 21.1.1
setuptools : 56.0.0
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : 3.0.1
lxml.etree : 4.6.3
html5lib : None
pymysql : 0.8.1
psycopg2 : None
jinja2 : 2.11.3
IPython : None
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : 3.4.3
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyxlsb : None
s3fs : None
scipy : 1.7.1
sqlalchemy : 1.3.24
tables : None
tabulate : 0.8.7
xarray : None
xlrd : None
xlwt : None
numba : None

Metadata

Metadata

Assignees

Labels

BugNA - MaskedArraysRelated to pd.NA and nullable extension arraysNumeric OperationsArithmetic, Comparison, and Logical operations

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

      翻译: