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] Indexing a non-RangeIndex with a numpy integer returns a slice, not an entry #12954

Closed
Tracked by #12793
wence- opened this issue Mar 16, 2023 · 2 comments · Fixed by #12955
Closed
Tracked by #12793

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

wence- opened this issue Mar 16, 2023 · 2 comments · Fixed by #12955
Assignees
Labels
bug Something isn't working Python Affects Python cuDF API.

Comments

@wence-
Copy link
Contributor

wence- commented Mar 16, 2023

Describe the bug

import cudf
import numpy as np

index = cudf.Index([1, 2], dtype="int64")
value = index[np.int32(0)]
print(type(value)) # => cudf.core.index.Int64Index
value = index[0]
print(type(value)) # => np.int64

Contrast, pandas, where indexing with a single value gives us a scalar in both cases.

Expected behavior

This should work, I think.

@wence- wence- added bug Something isn't working Needs Triage Need team to review and classify labels Mar 16, 2023
@wence- wence- self-assigned this Mar 16, 2023
@wence- wence- added Python Affects Python cuDF API. and removed Needs Triage Need team to review and classify labels Mar 16, 2023
wence- added a commit to wence-/cudf that referenced this issue Mar 16, 2023
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.
@vyasr
Copy link
Contributor

vyasr commented Mar 16, 2023

Does this belong with #12793 or is this more of a one-off?

@wence-
Copy link
Contributor Author

wence- commented Mar 16, 2023

This is a one-off, I think. I guess I could add it to the long list of "give me tagged unions" bugs in dynamic dispatch.

Edit: TBH, when I went through bugs for #12793 I didn't even think about indexing indices!

rapids-bot bot pushed a commit that referenced this issue Mar 21, 2023
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.

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

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

URL: #12955
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
None yet
Development

Successfully merging a pull request may close this issue.

2 participants