Skip to content

pandas cut() not working as expected in version 0.20.3 #17047

Closed
@HugoDLopes

Description

@HugoDLopes

Code Sample

>>> import pandas as pd
>>> 
>>> # Toy data
>>> series = pd.Series([0, 1, 5, 6, 10, None, np.nan])
>>> bins = [0, 5, 8]
>>> 
>>> pd.cut(series, bins=bins, include_lowest=True)

Out[23]:
0    (-0.001, 5.0]
1    (-0.001, 5.0]
2    (-0.001, 5.0]
3       (5.0, 8.0]
4              NaN
5              NaN
6              NaN
dtype: category
Categories (2, interval[float64]): [(-0.001, 5.0] < (5.0, 8.0]]

Problem description

It was expected that the lower boundary would be [0, 5] (for the first three instances). However, a value of -0.001 was "invented" (?). It worked in version 0.19.2 (with the output shown in Expected Output). Is there any bug? Is there anything I have to specify to make it work again as before?

Expected Output

0    [0, 5.0]
1    [0, 5.0]
2    [0, 5.0]
3    (5.0, 8.0]
4              NaN
5              NaN
6              NaN
dtype: category
Categories (2, interval[float64]): [ [0, 5.0] < (5.0, 8.0]]

Output of pd.show_versions()

INSTALLED VERSIONS ------------------ commit: None python: 3.5.2.final.0 python-bits: 64 OS: Linux OS-release: 4.4.0-79-generic machine: x86_64 processor: x86_64 byteorder: little LC_ALL: None LANG: en_US.UTF-8 LOCALE: en_US.UTF-8

pandas: 0.20.3
pytest: None
pip: 9.0.1
setuptools: 36.2.0
Cython: None
numpy: 1.13.1
scipy: 0.19.1
xarray: None
IPython: 5.1.0
sphinx: None
patsy: None
dateutil: 2.6.1
pytz: 2017.2
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: 2.0.0
openpyxl: 2.4.1
xlrd: 1.0.0
xlwt: 1.2.0
xlsxwriter: 0.9.8
lxml: None
bs4: None
html5lib: 0.999999999
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.9.6
s3fs: None
pandas_gbq: None
pandas_datareader: None

Metadata

Metadata

Assignees

No one assigned

    Labels

    Duplicate ReportDuplicate issue or pull requestIntervalInterval data typeRegressionFunctionality that used to work in a prior pandas version

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions