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

[BUG] LocIndexer of a DataFrame with a MultiIndex columns with a single label tuple returns DataFrame #13864

Closed
mroeschke opened this issue Aug 11, 2023 · 0 comments · Fixed by #13929
Assignees
Labels
bug Something isn't working Python Affects Python cuDF API.

Comments

@mroeschke
Copy link
Contributor

Describe the bug
LocIndexer of a DataFrame with a MultiIndex columns with a single label tuple returns DataFrame instead of a Series

Steps/Code to reproduce bug

In [50]: import cudf

In [51]: cudf.__version__
Out[51]: '23.10.00'

In [52]: dfmi = cudf.DataFrame([list('abcd'),
    ...: 
    ...:                      list('efgh'),
    ...: 
    ...:                      list('ijkl'),
    ...: 
    ...:                      list('mnop')],
    ...: 
    ...:                     columns=cudf.MultiIndex.from_product([['one', 'two'],
    ...: 
    ...:                                                         ['first', 'second']]))

In [53]: dfmi.loc[:, ('one', 'second')]
Out[53]: 
  (one, second)
0             b
1             f
2             j
3             n

In [54]: dfmi.to_pandas().loc[:, ('one', 'second')]
Out[54]: 
0    b
1    f
2    j
3    n
Name: (one, second), dtype: object

Expected behavior
Like pandas, a single tuple label should be treated like a scalar label instead of a container of labels and return a Series instead of a DataFrame

Environment overview (please complete the following information)

  • Environment location: Bare-metal
  • Method of cuDF install: conda
    • If method of install is [Docker], provide docker pull & docker run commands used

Environment details
Please run and paste the output of the cudf/print_env.sh script here, to gather any other relevant environment details

Additional context
Add any other context about the problem here.

@mroeschke mroeschke added bug Something isn't working Needs Triage Need team to review and classify labels Aug 11, 2023
@galipremsagar galipremsagar self-assigned this Aug 21, 2023
@galipremsagar galipremsagar added Python Affects Python cuDF API. and removed Needs Triage Need team to review and classify labels Aug 21, 2023
rapids-bot bot pushed a commit that referenced this issue Aug 22, 2023
Fixes: #13864 

This PR fixes an issue with `loc` indexer where some special handling needs to be done when `columns` is of type `MultiIndex`.

Authors:
  - GALI PREM SAGAR (https://github.com/galipremsagar)

Approvers:
  - Lawrence Mitchell (https://github.com/wence-)

URL: #13929
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Python Affects Python cuDF API.
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants