-
-
Notifications
You must be signed in to change notification settings - Fork 18.2k
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
CLN: Centralised _check_percentile #27584
Changes from 12 commits
69ef619
715ac7d
de8a4ab
7db44a4
350a624
4b4ca39
79c407d
146ebc5
8807706
b0a02e4
d4d0e88
7870f75
93a7970
5b0122f
946ee3f
3c56c6b
786e172
d81a08d
631a049
f66f314
4e399c6
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 |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
intended for public consumption | ||
""" | ||
from textwrap import dedent | ||
from typing import Dict | ||
from typing import Dict, Iterable, Union | ||
from warnings import catch_warnings, simplefilter, warn | ||
|
||
import numpy as np | ||
|
@@ -1102,6 +1102,37 @@ def _get_score(at): | |
return result | ||
|
||
|
||
def check_percentile(q: Union[float, Iterable[float]]) -> np.ndarray: | ||
""" | ||
Validate percentiles (used by describe and quantile). | ||
hedonhermdev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
This function checks if the given float oriterable of floats is a valid percentile otherwise raises a ValueError. | ||
|
||
Args | ||
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. Should be 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. Will update this asap |
||
---- | ||
q: float or iterable of floats | ||
A single percentile or an iterable of percentiles. | ||
|
||
Returns | ||
------- | ||
ndarray | ||
An ndarray of the percentiles if valid. | ||
|
||
Raises | ||
------ | ||
ValueError if percentiles are not in given interval([0, 1]). | ||
""" | ||
msg = "percentiles should all be in the interval [0, 1]. " "Try {0} instead." | ||
q_arr = np.asarray(q) | ||
if q_arr.ndim == 0: | ||
if not 0 <= q_arr <= 1: | ||
raise ValueError(msg.format(q_arr / 100.0)) | ||
else: | ||
if not all(0 <= qs <= 1 for qs in q_arr): | ||
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. for a large array this is going to be much less performant than |
||
raise ValueError(msg.format(q_arr / 100.0)) | ||
return q_arr | ||
|
||
|
||
# --------------- # | ||
# select n # | ||
# --------------- # | ||
|
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.
would this make more sense in validators?
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.
I think that's reasonable
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.
Should I shift it to utilts/_validators.py ?
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.
Yea let's do that
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.
Would renaming it to validate_percentile be better?