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
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion python/cudf/cudf/api/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,17 @@ def is_scalar(val):
cudf._lib.scalar.DeviceScalar,
cudf.core.tools.datetimes.DateOffset,
),
) or pd_types.is_scalar(val)
) or (
pd_types.is_scalar(val)
# Pytorch tensors advertise that they support the number
# protocol, and therefore return True for PyNumber_Check even
# when they have a shape. So, if we get through this, let's
# additionally check that if they have a shape property that
# it is empty.
# See https://github.com/pytorch/pytorch/issues/99646
# and https://github.com/pandas-dev/pandas/issues/52701
and len(getattr(val, "shape", ())) == 0
)


def _is_scalar_or_zero_d_array(val):
Expand Down