Skip to content
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

Partial indexing with list on MultiIndex with missing value includes them despite not being in the list #27104

Closed
toobaz opened this issue Jun 28, 2019 · 0 comments · Fixed by #37706
Labels
Indexing Related to indexing on series/frames, not to indexes themselves Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate MultiIndex
Milestone

Comments

@toobaz
Copy link
Member

toobaz commented Jun 28, 2019

Code Sample, a copy-pastable example if possible

In [2]: df = pd.DataFrame({'col':[1, 2, 3, 4, 5], 'ind1':['a','b','c','d',np.nan], 'ind2':[1,2,3,4,5] }).set_index(['ind1', 'ind2'])                                                                                                          

In [3]: df.loc['a']                                                                                                                                                                                                                           
Out[3]: 
      col
ind2     
1       1

In [4]: df.loc[['a']]                                                                                                                                                                                                                         
Out[4]: 
           col
ind1 ind2     
a    1       1
NaN  5       5

Problem description

Out[3] is correct, Out[4] is wrong - the NaN line should not be there.

From #15107.

Expected Output

Same as Out[3].

Output of pd.show_versions()

INSTALLED VERSIONS

commit : 45ea267
python : 3.7.3.candidate.1
python-bits : 64
OS : Linux
OS-release : 4.9.0-9-amd64
machine : x86_64
processor :
byteorder : little
LC_ALL : None
LANG : it_IT.UTF-8
LOCALE : it_IT.UTF-8

pandas : 0.25.0.dev0+824.g45ea26763
numpy : 1.16.4
pytz : 2016.7
dateutil : 2.8.0
pip : 9.0.1
setuptools : 41.0.1
Cython : 0.29.2
pytest : 3.0.6
hypothesis : 3.6.1
sphinx : 1.4.9
blosc : None
feather : None
xlsxwriter : 0.9.6
lxml.etree : 4.3.2
html5lib : 0.999999999
pymysql : None
psycopg2 : None
jinja2 : 2.10.1
IPython : 7.5.0
pandas_datareader: 0.2.1
bs4 : 4.5.3
bottleneck : 1.2.1
fastparquet : None
gcsfs : None
lxml.etree : 4.3.2
matplotlib : 3.0.2
numexpr : 2.6.9
openpyxl : 2.3.0
pandas_gbq : None
pyarrow : None
pytables : None
s3fs : None
scipy : 1.1.0
sqlalchemy : 1.0.15
tables : 3.4.4
xarray : None
xlrd : 1.0.0
xlwt : 1.3.0
xlsxwriter : 0.9.6

@toobaz toobaz added Indexing Related to indexing on series/frames, not to indexes themselves Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate MultiIndex labels Jun 28, 2019
@jreback jreback added this to the 1.2 milestone Nov 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Indexing Related to indexing on series/frames, not to indexes themselves Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate MultiIndex
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants