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

Add (implicit) handling for torch tensors in is_scalar #14623

Merged
merged 1 commit into from
Dec 13, 2023

Conversation

wence-
Copy link
Contributor

@wence- wence- commented Dec 13, 2023

Description

PyTorch tensors advertise that they support the number API, and hence answer "True" to the question pd.api.types.is_scalar(torch_tensor). This trips up some of our data ingest, since in as_index we check if the input is a scalar (and raise) before handing off to as_column. To handle this, if we get True back from pandas' is_scalar call, additionally check that the object has an empty shape attribute (if it exists).

See also:

Checklist

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

PyTorch tensors advertise that they support the number API, and hence
answer "True" to the question pd.api.types.is_scalar(torch_tensor).
This trips up some of our data ingest, since in as_index we check if
the input is a scalar (and raise) before handing off to as_column. To
handle this, if we get True back from pandas' is_scalar call,
additionally check that the object has an empty shape attribute (if it
exists).

See also:

- pytorch/pytorch#99646
- pandas-dev/pandas#52701
@wence- wence- requested a review from a team as a code owner December 13, 2023 09:57
@github-actions github-actions bot added the Python Affects Python cuDF API. label Dec 13, 2023
@wence-
Copy link
Contributor Author

wence- commented Dec 13, 2023

cc @shwina @puririshi98

Copy link
Contributor

@shwina shwina left a comment

Choose a reason for hiding this comment

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

Ugh but LGTM

@wence- wence- added bug Something isn't working non-breaking Non-breaking change labels Dec 13, 2023
@wence-
Copy link
Contributor Author

wence- commented Dec 13, 2023

/merge

@rapids-bot rapids-bot bot merged commit a894ca0 into rapidsai:branch-24.02 Dec 13, 2023
67 checks passed
@wence- wence- deleted the wence/fix/torch-isscalar branch December 13, 2023 16:53
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
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

2 participants