Skip to content

BUG: Index.isin inconsistency with missing value #30677

Closed
@proost

Description

@proost

DataFrame case,

In [15]: df = pd.DataFrame({'num_legs': [None, 4], 'num_wings': [np.nan, 0]},ind
    ...: ex=['falcon', 'dog'])                                                  

In [16]: df.isin([np.nan, None])                                                
Out[16]: 
        num_legs  num_wings
falcon      True       True
dog        False      False

In [17]: df.isin([None, None])                                                  
Out[17]: 
        num_legs  num_wings
falcon      True       True
dog        False      False

In [18]: df.isin([np.nan, np.nan])                                              
Out[18]: 
        num_legs  num_wings
falcon      True       True
dog        False      False

But Index case,

In [20]: idx = Index([np.nan,'a','b', None])                                    

In [21]: idx.isin([None])                                                       
Out[21]: array([False, False, False,  True])

In [22]: idx.isin([np.nan])                                                     
Out[22]: array([ True, False, False, False])

Problem description

'.isin' handle NA values differently depending on object types. 'np.nan' and 'None' both are NA value. so, 'Index.isin' do not distinguish 'np.nan' and 'None' like 'DataFrame' case.

Expected Output

In [20]: idx = Index([np.nan,'a','b', None])                                    

In [21]: idx.isin([None])                                                       
Out[21]: array([True, False, False,  True])

In [22]: idx.isin([np.nan])                                                     
Out[22]: array([ True, False, False, True])

Output of pd.show_versions()

INSTALLED VERSIONS

commit : None
python : 3.7.4.final.0
python-bits : 64
OS : Linux
OS-release : 5.0.0-37-generic
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : ko_KR.UTF-8
LOCALE : ko_KR.UTF-8

pandas : 0.25.1
numpy : 1.17.2
pytz : 2019.3
dateutil : 2.8.0
pip : 19.2.3
setuptools : 41.4.0
Cython : 0.29.13
pytest : 5.2.1
hypothesis : None
sphinx : 2.2.0
blosc : None
feather : None
xlsxwriter : 1.2.1
lxml.etree : 4.4.1
html5lib : 1.0.1
pymysql : None
psycopg2 : None
jinja2 : 2.10.3
IPython : 7.8.0
pandas_datareader: None
bs4 : 4.8.0
bottleneck : 1.2.1
fastparquet : None
gcsfs : None
lxml.etree : 4.4.1
matplotlib : 3.1.1
numexpr : 2.7.0
odfpy : None
openpyxl : 3.0.0
pandas_gbq : None
pyarrow : None
pytables : None
s3fs : None
scipy : 1.3.1
sqlalchemy : 1.3.9
tables : 3.5.2
xarray : None
xlrd : 1.2.0
xlwt : 1.3.0
xlsxwriter : 1.2.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions