-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: fixed wrong order of ordered labels in pd.cut() #16466
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you add:
- a whatsnew note (0.20.2 reshaping bug fix)
- the test from the original issue
@jreback happy to do that, can you tell me how/where to add the what's new, and what you're looking for in terms of the original test? all i know is it passes. |
doc/source/whatsnew/v0.20.2.txt you copy the test from the original issue and assert that it is correct now (you construct the expected) and compare vs running |
Ok, the what's new is straightforward, in terms of the test, do you just want me to include the output in the original issue? or an actual test in |
Codecov Report
@@ Coverage Diff @@
## master #16466 +/- ##
=======================================
Coverage 90.42% 90.42%
=======================================
Files 161 161
Lines 51027 51027
=======================================
Hits 46142 46142
Misses 4885 4885
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #16466 +/- ##
==========================================
+ Coverage 90.75% 90.79% +0.04%
==========================================
Files 161 161
Lines 51073 51063 -10
==========================================
+ Hits 46350 46365 +15
+ Misses 4723 4698 -25
Continue to review full report at Codecov.
|
that's exactly the point. the test should succeed now! and failed before the fix. |
Pre-fix:
Post-fix:
|
@economy so make a test out of that. |
Gotcha, sorry for the confusion. |
doc/source/whatsnew/v0.20.2.txt
Outdated
@@ -37,6 +37,7 @@ Bug Fixes | |||
~~~~~~~~~ | |||
|
|||
- Bug in using ``pathlib.Path`` or ``py.path.local`` objects with io functions (:issue:`16291`) | |||
- Bug in ``pd.cut`` when ``labels`` are set (:issue:`16459`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug in pd.cut
does not preserve label ordering when labels
are passed
pandas/tests/reshape/test_tile.py
Outdated
@@ -211,12 +211,18 @@ def test_cut_pass_labels(self): | |||
|
|||
result = cut(arr, bins, labels=labels) | |||
exp = Categorical(['Medium'] + 4 * ['Small'] + ['Medium', 'Large'], | |||
categories=labels, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this causes a lint error (needs an indent)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm. minor comments. rebase on master, ping when green.
@jreback finally had a chance to get to this. should be green now |
@economy looks like a conflict in the whatsnew file. Can you rebase? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor doc comments.
doc/source/whatsnew/v0.20.2.txt
Outdated
- Fixed a compatibility issue with IPython 6.0's tab completion showing deprecation warnings on Categoricals (:issue:`16409`) | ||
|
||
- Bug in ``pd.cut`` when ``labels`` are set (:issue:`16459`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe add incorrect ordering resulted
pandas/tests/reshape/test_tile.py
Outdated
@@ -219,6 +220,12 @@ def test_cut_pass_labels(self): | |||
exp = Categorical.from_codes([1] + 4 * [0] + [1, 2], labels) | |||
tm.assert_categorical_equal(result, exp) | |||
|
|||
labels = ['Good', 'Medium', 'Bad'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add issue reference here
thanks! |
closes pandas-dev#16459 Author: economy <[email protected]> This patch had conflicts when merged, resolved by Committer: Jeff Reback <[email protected]> Closes pandas-dev#16466 from economy/fix_cut and squashes the following commits: 29128b3 [economy] comments and whatsnew edits 3898b72 [economy] BUG: fixed wrong order of ordered labels in pd.cut() (cherry picked from commit d419be4)
closes #16459 Author: economy <[email protected]> This patch had conflicts when merged, resolved by Committer: Jeff Reback <[email protected]> Closes #16466 from economy/fix_cut and squashes the following commits: 29128b3 [economy] comments and whatsnew edits 3898b72 [economy] BUG: fixed wrong order of ordered labels in pd.cut() (cherry picked from commit d419be4)
closes pandas-dev#16459 Author: economy <[email protected]> This patch had conflicts when merged, resolved by Committer: Jeff Reback <[email protected]> Closes pandas-dev#16466 from economy/fix_cut and squashes the following commits: 29128b3 [economy] comments and whatsnew edits 3898b72 [economy] BUG: fixed wrong order of ordered labels in pd.cut()
closes pandas-dev#16459 Author: economy <[email protected]> This patch had conflicts when merged, resolved by Committer: Jeff Reback <[email protected]> Closes pandas-dev#16466 from economy/fix_cut and squashes the following commits: 29128b3 [economy] comments and whatsnew edits 3898b72 [economy] BUG: fixed wrong order of ordered labels in pd.cut()
git diff upstream/master --name-only -- '*.py' | flake8 --diff
Changes to how
cut
instantiatesCategorical
when a list of labels are passed to it, and thetest_cut_pass_labels
test for it. If labels are passed in as aCategorical
already, behavior isn't altered at all, but if the user specifies a list of labels, the rank ordering of those labels is preserved incut
.