Description
-
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.
Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.
Code Sample, a copy-pastable example
import pandas as pd
nbins = 42
maxs = [96, 97, 98]
for max in maxs:
data = [-max, 0, max]
bins = pd.cut(data, nbins, labels=False)
print("Data: ", data)
print("Bins: ", bins, "\n")
Problem description
According to documentation, I would expect the 0
value to go to the bin 20
. For max == 96
and max == 98
it does go to the bin 20
, however, when max == 97
for some reason 0
goes to the bin 21
:
Data: [-96, 0, 96]
Bins: [ 0 20 41]
Data: [-97, 0, 97]
Bins: [ 0 21 41]
Data: [-98, 0, 98]
Bins: [ 0 20 41]
Feels like a bug, or may be I'm missing something on the docs that explains such a cut()
behavior. Would appreciate any help on this. Thanks.
Expected Output
Data: [-96, 0, 96]
Bins: [ 0 20 41]
Data: [-97, 0, 97]
Bins: [ 0 20 41]
Data: [-98, 0, 98]
Bins: [ 0 20 41]
Output of pd.show_versions()
INSTALLED VERSIONS
commit : None
python : 3.6.8.final.0
python-bits : 64
OS : Darwin
OS-release : 19.2.0
machine : x86_64
processor : i386
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
pandas : 1.0.5
numpy : 1.16.1
pytz : 2018.9
dateutil : 2.8.0
pip : 20.0.2
setuptools : 40.6.3
Cython : None
pytest : 4.1.1
hypothesis : None
sphinx : 2.4.4
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.10
IPython : 7.8.0
pandas_datareader: None
bs4 : None
bottleneck : None
fastparquet : None
gcsfs : None
lxml.etree : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
pytest : 4.1.1
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : 1.2.0
xlwt : None
xlsxwriter : None
numba : None