-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
ERR: Improved error message and updated doc in cut/qcut (issue 13318) #16982
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,7 +44,7 @@ def cut(x, bins, right=True, labels=None, retbins=False, precision=3, | |
labels : array or boolean, default None | ||
Used as labels for the resulting bins. Must be of the same length as | ||
the resulting bins. If False, return only integer indicators of the | ||
bins. | ||
bins. If True, raises an error. | ||
retbins : bool, optional | ||
Whether to return the bins or not. Can be useful if bins is given | ||
as a scalar. | ||
|
@@ -155,7 +155,7 @@ def qcut(x, q, labels=None, retbins=False, precision=3, duplicates='raise'): | |
labels : array or boolean, default None | ||
Used as labels for the resulting bins. Must be of the same length as | ||
the resulting bins. If False, return only integer indicators of the | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same |
||
bins. | ||
bins. If True, raises an error. | ||
retbins : bool, optional | ||
Whether to return the (bins, labels) or not. Can be useful if bins | ||
is given as a scalar. | ||
|
@@ -245,7 +245,10 @@ def _bins_to_cuts(x, bins, right=True, labels=None, | |
has_nas = na_mask.any() | ||
|
||
if labels is not False: | ||
if labels is None: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would do something more along the lines
|
||
if labels is True: | ||
raise ValueError("User desired bin labels must be passed " | ||
"in as an argument, not just `True`") | ||
elif labels is None: | ||
labels = _format_labels(bins, precision, right=right, | ||
include_lowest=include_lowest, | ||
dtype=dtype) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -326,6 +326,12 @@ def test_series_retbins(self): | |
ordered=True) | ||
tm.assert_series_equal(result, expected) | ||
|
||
def test_qcut_labels_true(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cycle thru a few more things that are not valid (you can use parametrize) , e.g. 'foo', 1 |
||
# issue 13318 | ||
values = list(range(10)) | ||
with tm.assert_raises_regex(ValueError, "True"): | ||
qcut(values, 5, labels=True) | ||
|
||
def test_qcut_duplicates_bin(self): | ||
# GH 7751 | ||
values = [0, 0, 0, 0, 1, 2, 3] | ||
|
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.
how about
labels: array or False, default None