Skip to content

BUG: cut does not respect order of passed labels #16459

Closed
@ProsperousHeart

Description

@ProsperousHeart

This issue was found when working on #16432

    Examples
    --------
    >>> pd.cut(np.array([.2, 1.4, 2.5, 6.2, 9.7, 2.1]), 3, retbins=True)
    ([(0.19, 3.367], (0.19, 3.367], (0.19, 3.367], (3.367, 6.533], (6.533, 9.7], (0.19, 3.367]]
    Categories (3, interval[float64]): [(0.19, 3.367] < (3.367, 6.533] < 
    ...        (6.533, 9.7]], array([ 0.1905    ,  3.36666667,  6.53333333,
    ...         9.7       ]))

    >>> result = pd.cut(np.array([.2, 1.4, 2.5, 6.2, 9.7, 2.1]),
    ...                          3, labels=["good","medium","bad"])
    [good, good, good, medium, bad, good]
    Categories (3, object): [good < medium < bad]

Problem description

When running pytest -x --doctest-modules core/reshape/tile.py against the work inside of the "reshape-3439" branch, we see the following:

(pandas_dev) C:\Users\kkeeton\AppData\Local\conda\conda\envs\pandas_dev\Lib\site-packages\pandas>pytest -x --doctest-modules core/reshape/tile.py
============================= test session starts =============================
platform win32 -- Python 3.6.1, pytest-3.0.7, py-1.4.33, pluggy-0.4.0
rootdir: C:\Users\kkeeton\AppData\Local\conda\conda\envs\pandas_dev\Lib\site-packages\pandas, inifile:
plugins: cov-2.3.1
collected 2 items

core\reshape\tile.py F

================================== FAILURES ===================================
___________________ [doctest] pandas.core.reshape.tile.cut ____________________
072     the resulting Categorical object
073
074
075     Examples
076     --------
077     >>> pd.cut(np.array([.2, 1.4, 2.5, 6.2, 9.7, 2.1]), 3, retbins=True)
078     ([(0.19, 3.367], (0.19, 3.367], (0.19, 3.367], (3.367, 6.533], (6.533, 9.7], (0.19, 3.367]]
079     Categories (3, interval[float64]): [(0.19, 3.367] < (3.367, 6.533] < (6.533, 9.7]], array([ 0.1905    ,  3.36666667,  6.53333333,  9.7       ]))
080
081     >>> pd.cut(np.array([.2, 1.4, 2.5, 6.2, 9.7, 2.1]),
Expected:
    [good, good, good, medium, bad, good]
    Categories (3, object): [good < medium < bad]
Got:
    [good, good, good, medium, bad, good]
    Categories (3, object): [bad < good < medium]

C:\Users\kkeeton\AppData\Local\conda\conda\envs\pandas_dev\Lib\site-packages\pandas\core\reshape\tile.py:81: DocTestFailure

This is backwards.

Expected Output

Should clear this - this is not an issue.

Output of pd.show_versions()

Unable to run the pd.show_versions()

Metadata

Metadata

Assignees

No one assigned

    Labels

    CategoricalCategorical 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