Skip to content

ERR: Improve error message in validate_percentile #51475

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

Merged
merged 26 commits into from
Apr 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
7a59553
fixed: valueError
ShashwatAgrawal20 Feb 18, 2023
e20e1dc
Merge branch 'main' into validate_percentile_51436
ShashwatAgrawal20 Feb 18, 2023
761492a
Merge branch 'main' into validate_percentile_51436
ShashwatAgrawal20 Feb 18, 2023
afa5ee5
Merge branch 'main' into validate_percentile_51436
ShashwatAgrawal20 Feb 19, 2023
fd8d6d0
shorten msg
ShashwatAgrawal20 Feb 19, 2023
466ff31
Merge branch 'main' into validate_percentile_51436
ShashwatAgrawal20 Feb 20, 2023
c8f686c
Merge branch 'main' into validate_percentile_51436
ShashwatAgrawal20 Feb 21, 2023
4458985
Merge branch 'main' into validate_percentile_51436
ShashwatAgrawal20 Mar 3, 2023
48e94bf
Added test file
ShashwatAgrawal20 Mar 12, 2023
64fcc9e
Merge branch 'main' into validate_percentile_51436
ShashwatAgrawal20 Mar 14, 2023
9757aa1
Merge branch 'main' into validate_percentile_51436
ShashwatAgrawal20 Mar 14, 2023
96c8673
refactored test file
ShashwatAgrawal20 Mar 14, 2023
0faa76e
Merge branch 'main' into validate_percentile_51436
ShashwatAgrawal20 Mar 16, 2023
faf2978
Merge branch 'main' into validate_percentile_51436
ShashwatAgrawal20 Mar 22, 2023
46141ec
moved test to quantile file
ShashwatAgrawal20 Mar 22, 2023
9a0aae0
modified test file
ShashwatAgrawal20 Mar 26, 2023
f295e32
Merge branch 'main' into validate_percentile_51436
ShashwatAgrawal20 Mar 26, 2023
c682cdb
Merge branch 'main' into validate_percentile_51436
ShashwatAgrawal20 Mar 28, 2023
ed1935e
Merge branch 'main' into validate_percentile_51436
ShashwatAgrawal20 Mar 30, 2023
e933efd
Merge branch 'main' into validate_percentile_51436
ShashwatAgrawal20 Mar 31, 2023
e92be61
Merge branch 'main' into validate_percentile_51436
ShashwatAgrawal20 Apr 1, 2023
f2fb73e
Merge branch 'main' into validate_percentile_51436
ShashwatAgrawal20 Apr 2, 2023
ba7aeb0
Merge branch 'main' into validate_percentile_51436
ShashwatAgrawal20 Apr 3, 2023
24b2e3d
Merge branch 'pandas-dev:main' into validate_percentile_51436
ShashwatAgrawal20 Apr 4, 2023
ce543f6
Merge branch 'main' into validate_percentile_51436
ShashwatAgrawal20 Apr 5, 2023
5a08a2c
Merge branch 'main' into validate_percentile_51436
ShashwatAgrawal20 Apr 7, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions pandas/tests/series/methods/test_quantile.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ def test_quantile(self, datetime_series):
with pytest.raises(ValueError, match=msg):
datetime_series.quantile(invalid)

s = Series(np.random.randn(100))
percentile_array = [-0.5, 0.25, 1.5]
with pytest.raises(ValueError, match=msg):
s.quantile(percentile_array)

def test_quantile_multi(self, datetime_series):
qs = [0.1, 0.9]
result = datetime_series.quantile(qs)
Expand Down
9 changes: 5 additions & 4 deletions pandas/util/_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,12 +329,13 @@ def validate_percentile(q: float | Iterable[float]) -> np.ndarray:
q_arr = np.asarray(q)
# Don't change this to an f-string. The string formatting
# is too expensive for cases where we don't need it.
msg = "percentiles should all be in the interval [0, 1]. Try {} instead."
msg = "percentiles should all be in the interval [0, 1]"
if q_arr.ndim == 0:
if not 0 <= q_arr <= 1:
raise ValueError(msg.format(q_arr / 100.0))
elif not all(0 <= qs <= 1 for qs in q_arr):
raise ValueError(msg.format(q_arr / 100.0))
raise ValueError(msg)
else:
if not all(0 <= qs <= 1 for qs in q_arr):
raise ValueError(msg)
return q_arr


Expand Down