Skip to content

BUG: Fix return of missing values when applying loc to single level of MultiIndex #37706

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

Merged
merged 6 commits into from
Nov 9, 2020

Conversation

phofl
Copy link
Member

@phofl phofl commented Nov 8, 2020

This confused -1 representing missing values in input with the -1 signaling which components to exclude from output.

@phofl phofl added Indexing Related to indexing on series/frames, not to indexes themselves MultiIndex labels Nov 8, 2020
Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm. ping on green.

# GH: 27104
df = DataFrame(
{"col": [1, 2, 5], "ind1": ["a", "d", np.nan], "ind2": [1, 4, 5]}
).set_index(["ind1", "ind2"])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you also select df.loc['a'] as the first case in OP (which is working). can parameterize if easy.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parametrization would be ugly, because Index needs new definition. Added the test below.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kk totally fine, i always ask, but like you did push back if its non-trivial or would make it less obvious.

@jreback jreback added this to the 1.2 milestone Nov 9, 2020
@phofl
Copy link
Member Author

phofl commented Nov 9, 2020

cc @jreback green

Thanks for merging master

phofl added 2 commits November 9, 2020 18:52
� Conflicts:
�	doc/source/whatsnew/v1.2.0.rst
@@ -466,7 +466,8 @@ Indexing
- Bug in indexing on a :class:`Series` or :class:`DataFrame` with a :class:`MultiIndex` with a level named "0" (:issue:`37194`)
- Bug in :meth:`Series.__getitem__` when using an unsigned integer array as an indexer giving incorrect results or segfaulting instead of raising ``KeyError`` (:issue:`37218`)
- Bug in :meth:`Index.where` incorrectly casting numeric values to strings (:issue:`37591`)
- Bug in :meth:`Series.loc` and :meth:`DataFrame.loc` raises when numeric label was given for object :class:`Index` although label was in :class:`Index` (:issue:`26491`)
- Bug in :meth:`DataFrame.loc` returned requested key plus missing values when ``loc`` was applied to single level from :class:`MultiIndex` (:issue:`27104`)
- Bug in :meth:`Series.loc` and :meth:`DataFrame.loc` raises when numeric label was given for object :class:`Index` although label was in :class:`Index` (:issue:`26491`)>>>>>>> master
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems there is a >>>>>>> master?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like merge went wrong. Is fixed now. Thanks

@charlesdong1991 charlesdong1991 merged commit 0a854b8 into pandas-dev:master Nov 9, 2020
@charlesdong1991
Copy link
Member

very nice @phofl

@phofl phofl deleted the 27104 branch November 9, 2020 20:29
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 MultiIndex
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Partial indexing with list on MultiIndex with missing value includes them despite not being in the list
3 participants