Pandas version checks
-
[X] I have checked that this issue has not already been reported.
-
[X] I have confirmed this bug exists on the latest version of pandas.
-
[ ] I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
import pandas as pd
import torch
pd.api.types.is_scalar(torch.tensor([0, 1, 2])) # returns True
Issue Description
is_scalar
reports True
for torch tensors (of any dimensionality as far as I can tell).
Expected Behavior
I would expect this function to return False
for torch tensors.
Installed Versions
Comment From: mroeschke
Here are the "scalar" checks
https://github.com/pandas-dev/pandas/blob/433f34b118f3d1a3fc439553edcb5c0ac1ecb3c0/pandas/_libs/lib.pyx#L221-L243
Debugging locally, it's interesting/odd that PySequence_Check
returns False and PyNumber_Check
returns True for a torch.Tensor
. I would expect this to be the opposite for both checks
Comment From: mroeschke
Opened up https://github.com/pytorch/pytorch/issues/99646
Comment From: akashdasp
is this is the issue with the pandas library it has the issue with the torch?
Comment From: mroeschke
So it seems that from https://github.com/pytorch/pytorch/issues/99646 that this is intended/won't fix behavior, and I don't think pandas can special case torch objects in this function as torch isn't a related dependency in pandas.
At best, maybe pandas could document that this is function is only reliable for python stdlib, numpy and pandas objects only?