-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
ERR: qcut uniquess checking (try 2) #15000
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
Closed
Closed
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
bee981c
adding 'duplicates' option to qcut
ashishsingal1 a2dd8ce
fixing duplicates check
ashishsingal1 0b8efeb
Update tile.py
ashishsingal1 3f98abc
Update tile.py
ashishsingal1 1ce77d0
Update test_tile.py
ashishsingal1 2161518
Update tile.py
ashishsingal1 3dbc416
Update v0.20.0.txt
ashishsingal1 2c5bc35
added duplicates='raise' test. other fixes to qcut for duplicates='ra…
ashishsingal1 221c0b3
Update tile.py
ashishsingal1 42bf482
Update tile.py
ashishsingal1 b6bf401
Update v0.20.0.txt
ashishsingal1 698b4ec
Update tile.py
ashishsingal1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -129,7 +129,7 @@ def cut(x, bins, right=True, labels=None, retbins=False, precision=3, | |
series_index, name) | ||
|
||
|
||
def qcut(x, q, labels=None, retbins=False, precision=3): | ||
def qcut(x, q, labels=None, retbins=False, precision=3, duplicates='raise'): | ||
""" | ||
Quantile-based discretization function. Discretize variable into | ||
equal-sized buckets based on rank or based on sample quantiles. For example | ||
|
@@ -151,6 +151,10 @@ def qcut(x, q, labels=None, retbins=False, precision=3): | |
as a scalar. | ||
precision : int | ||
The precision at which to store and display the bins labels | ||
duplicates : {default 'raise', 'drop'}, optional | ||
If bin edges are not unique, raise ValueError or drop non-uniques. | ||
|
||
.. versionadded:: 0.20.0 | ||
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. There needs to be a whiteline above this one (rst specifics ...) 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. There needs to be a blank line above |
||
|
||
Returns | ||
------- | ||
|
@@ -187,22 +191,32 @@ def qcut(x, q, labels=None, retbins=False, precision=3): | |
bins = algos.quantile(x, quantiles) | ||
fac, bins = _bins_to_cuts(x, bins, labels=labels, | ||
precision=precision, include_lowest=True, | ||
dtype=dtype) | ||
dtype=dtype, duplicates=duplicates) | ||
|
||
return _postprocess_for_cut(fac, bins, retbins, x_is_series, | ||
series_index, name) | ||
|
||
|
||
def _bins_to_cuts(x, bins, right=True, labels=None, | ||
precision=3, include_lowest=False, | ||
dtype=None): | ||
dtype=None, duplicates='raise'): | ||
|
||
if duplicates not in ['raise', 'drop']: | ||
raise ValueError("invalid value for 'duplicates' parameter, " | ||
"valid options are: raise, drop") | ||
|
||
unique_bins = algos.unique(bins) | ||
if len(unique_bins) < len(bins): | ||
if duplicates == 'raise': | ||
raise ValueError("Bin edges must be unique: {}. You " | ||
"can drop duplicate edges by setting " | ||
"'duplicates' param".format(repr(bins))) | ||
else: | ||
bins = unique_bins | ||
|
||
side = 'left' if right else 'right' | ||
ids = bins.searchsorted(x, side=side) | ||
|
||
if len(algos.unique(bins)) < len(bins): | ||
raise ValueError('Bin edges must be unique: %s' % repr(bins)) | ||
|
||
if include_lowest: | ||
ids[x == bins[0]] = 1 | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 test for
duplicates='raise'
(the default) as well? (assert that it raises a ValueError)