-
-
Notifications
You must be signed in to change notification settings - Fork 19.1k
Description
Pandas version checks
-
I have checked that this issue has not already been reported.
-
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 random
import pandas as pd
df=pd.DataFrame([[0,1],[2,3]])
random.choice(df.index)
Issue Description
This code produces the ValueError shown below. When I use python 3.10.x or 3.11.10, the error does not occur. I don't understand why the behavior would be different for Python 3.11.0.
ValueError Traceback (most recent call last)
Cell In[3], line 5
3 df=pd.DataFrame([[0,1],[2,3]])
4 pd.version
----> 5 random.choice(df.index)
File ~/miniconda3/envs/py3110/lib/python3.11/random.py:369, in Random.choice(self, seq)
367 def choice(self, seq):
368 """Choose a random element from a non-empty sequence."""
--> 369 if not seq:
370 raise IndexError('Cannot choose from an empty sequence')
371 return seq[self._randbelow(len(seq))]
File ~/miniconda3/envs/py3110/lib/python3.11/site-packages/pandas/core/indexes/base.py:3190, in Index.nonzero(self)
3188 @Final
3189 def nonzero(self) -> NoReturn:
-> 3190 raise ValueError(
3191 f"The truth value of a {type(self).name} is ambiguous. "
3192 "Use a.empty, a.bool(), a.item(), a.any() or a.all()."
3193 )
ValueError: The truth value of a RangeIndex is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
Expected Behavior
Should not raise an error
Installed Versions
INSTALLED VERSIONS
commit : 0691c5c
python : 3.11.0
python-bits : 64
OS : Darwin
OS-release : 24.1.0
Version : Darwin Kernel Version 24.1.0: Thu Oct 10 21:03:15 PDT 2024; root:xnu-11215.41.3~2/RELEASE_ARM64_T6000
machine : arm64
processor : arm
byteorder : little
LC_ALL : None
LANG : None
LOCALE : None.UTF-8
pandas : 2.2.3
numpy : 2.2.1
pytz : 2024.1
dateutil : 2.9.0.post0
pip : 24.2
Cython : None
sphinx : None
IPython : 8.31.0
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : None
blosc : None
bottleneck : 1.4.2
dataframe-api-compat : None
fastparquet : None
fsspec : None
html5lib : None
hypothesis : None
gcsfs : None
jinja2 : None
lxml.etree : None
matplotlib : None
numba : None
numexpr : 2.10.1
odfpy : None
openpyxl : None
pandas_gbq : None
psycopg2 : None
pymysql : None
pyarrow : None
pyreadstat : None
pytest : None
python-calamine : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlsxwriter : None
zstandard : None
tzdata : 2023.3
qtpy : None
pyqt5 : None