You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When a user wants to call pd.cut with a set of labels that includes duplicate values, they must set ordered to False and set labels to the series of strings to be used.
But running the sample code above, with ordered set to False and labels set to a series, gives this output:
Traceback (most recent call last):
File "/Users/mark/PycharmProjects/temp/bug1/cut_test.py", line 8, in <module>
print(pd.cut(test.row_value, cuts.cut_value, labels=cuts.cut_label[:-1], ordered=False))
File "/Users/mark/PycharmProjects/temp/bug1/venv/lib/python3.7/site-packages/pandas/core/reshape/tile.py", line 284, in cut
ordered=ordered,
File "/Users/mark/PycharmProjects/temp/bug1/venv/lib/python3.7/site-packages/pandas/core/reshape/tile.py", line 384, in _bins_to_cuts
if not ordered and not labels:
File "/Users/mark/PycharmProjects/temp/bug1/venv/lib/python3.7/site-packages/pandas/core/generic.py", line 1327, in __nonzero__
f"The truth value of a {type(self).__name__} is ambiguous. "
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
Process finished with exit code 1
Expected Output
The expected output is a series of strings taken from the labels list, as documented.
You can see from the Traceback that the error occurs at line 384 of tile.py. which is
if not ordered and not labels:
If that line is changed to
if not ordered and labels is None:
then running the sample code again gives the correct output:
0 even
1 odd
2 odd
3 even
4 odd
Name: row_value, dtype: category
Categories (2, object): ['even', 'odd']
Process finished with exit code 0
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of pandas.
(optional) I have confirmed this bug exists on the master branch of pandas.
Code Sample, a copy-pastable example
Problem description
When a user wants to call pd.cut with a set of labels that includes duplicate values, they must set ordered to False and set labels to the series of strings to be used.
But running the sample code above, with ordered set to False and labels set to a series, gives this output:
Expected Output
The expected output is a series of strings taken from the labels list, as documented.
You can see from the Traceback that the error occurs at line 384 of tile.py. which is
If that line is changed to
then running the sample code again gives the correct output:
Output of
pd.show_versions()
INSTALLED VERSIONS
commit : 2a7d332
python : 3.7.3.final.0
python-bits : 64
OS : Darwin
OS-release : 19.5.0
Version : Darwin Kernel Version 19.5.0: Tue May 26 20:41:44 PDT 2020; root:xnu-6153.121.2~2/RELEASE_X86_64
machine : x86_64
processor : i386
byteorder : little
LC_ALL : None
LANG : None
LOCALE : en_CA.UTF-8
pandas : 1.1.2
numpy : 1.19.2
pytz : 2020.1
dateutil : 2.8.1
pip : 20.2.3
setuptools : 50.3.0
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : None
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : None
The text was updated successfully, but these errors were encountered: