-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Calling qcut with too many duplicates now gives an informative error #9030
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 |
---|---|---|
|
@@ -165,6 +165,10 @@ def qcut(x, q, labels=None, retbins=False, precision=3): | |
else: | ||
quantiles = q | ||
bins = algos.quantile(x, quantiles) | ||
if len(algos.unique(bins)) < len(bins): | ||
bins_sorted = np.sort(bins, axis=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. you can do this as a set operation 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. That doesn't work. Say bins = [0,0,0,1,1,1]. We want [0,1]. (set(bins)-set(unique(bins)) gives set([]). Something like it should, but I can't think of it at the moment. |
||
bins_dup = algos.unique(bins_sorted[bins_sorted[1:] == bins_sorted[:-1]]) | ||
raise ValueError('One or more quantiles consists entirely of a repeated value: %s' % repr(bins_dup)) | ||
return _bins_to_cuts(x, bins, labels=labels, retbins=retbins,precision=precision, | ||
include_lowest=True) | ||
|
||
|
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.
pls move this to 0.16.0