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

Correctly handle scalar indices in Index.__getitem__ #12955

Merged
merged 4 commits into from
Mar 21, 2023

Conversation

wence-
Copy link
Contributor

@wence- wence- commented Mar 16, 2023

Description

It is not sufficient to check for isinstance(i, int) since the index may be a numpy type for which this check is False. Instead, invert the condition and check if the return value from _get_elements_from_column is a Column, in which case we should get an Index back.

Closes #12954.

Checklist

  • I am familiar with the Contributing Guidelines.
  • New or existing tests cover these changes.
  • The documentation is up to date with these changes.

It is not sufficient to check for isinstance(i, int) since the index
may be a numpy type for which this check is False. Instead, invert the
condition and check if the return value from _get_elements_from_column
is a Column, in which case we should get an Index back.

Closes rapidsai#12954.
@wence- wence- added bug Something isn't working non-breaking Non-breaking change labels Mar 16, 2023
@wence- wence- self-assigned this Mar 16, 2023
@wence- wence- requested a review from a team as a code owner March 16, 2023 15:30
@github-actions github-actions bot added the Python Affects Python cuDF API. label Mar 16, 2023
Copy link
Contributor

@galipremsagar galipremsagar left a comment

Choose a reason for hiding this comment

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

LGTM, one minor pytest comment.

python/cudf/cudf/tests/test_index.py Show resolved Hide resolved
@wence-
Copy link
Contributor Author

wence- commented Mar 21, 2023

/merge

@wence- wence- changed the title Correctly handle scalar indices in Index.__getitem__ Correctly handle scalar indices in Index.__getitem__ Mar 21, 2023
@rapids-bot rapids-bot bot merged commit f567cf5 into rapidsai:branch-23.04 Mar 21, 2023
@wence- wence- deleted the wence/fix/issue-12954 branch March 21, 2023 22:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working non-breaking Non-breaking change Python Affects Python cuDF API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Indexing a non-RangeIndex with a numpy integer returns a slice, not an entry
2 participants