-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
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
Using .loc
with MultiIndex containing np.nan
unexpected behavior
#43814
Comments
Please provide a minimal reproducible example, see https://matthewrocklin.com/blog/work/2018/02/28/minimal-bug-reports |
Edited the original report. |
Are that many rows necessary? Is the groupby necessary to reproduce? An example is minimal if you can't remove anything without causing the bug to disappear |
I got to the finding via the use of
Maybe not, that's at least the minimal example I prepared to report this. |
Please trim your example down then. I can only speak for myself but my motivation decreases significantly if the example is unnecessary complicated and contains a lot of other function calls. |
I updated the original report again. |
It would be great if you could remove the groupby if its not necessary. Otherwise this looks good now |
The |
Sorry misread your previous answer |
I have checked this on the latest version, same |
This is a regression caused by #35852 |
take |
Can't reproduce this either now. I might have focused only on the factorize function. |
removing milestone |
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
Issue Description
This issue is a follow-up of the discussion in this SO question.
It appears to be a bug, but if not, meaning, if this is desired behavior it should be documented.
As shown in the
Reproducible Example
, after groupingx
data on thetemp_playlist
andobjId
columns, there is a MultiIndex(0, nan)
. This index is meaningful and I wanted to access the data via it as I can perform with any other index fromagg_df.index
asagg_df.loc[<index_pos>]
. This is not possible for the index containing thenan
(agg_info_df.loc[agg_info_df.index[-1]]
). However, it does work if that same index is provided in a list of indices. So this seems at least inconsistent if not a bug entirely.For more info, please consult the SO question, especially this answer.
Expected Behavior
agg_info_df.loc[(0, np.nan)]
should return[2, 4]
Installed Versions
python 3.8.5, pandas 1.3.1, numpy 1.20.3
The text was updated successfully, but these errors were encountered: