Throw a clear error for degenerate-length data vectors (fixes #121)#206
Open
JohnCobbler wants to merge 1 commit into
Open
Throw a clear error for degenerate-length data vectors (fixes #121)#206JohnCobbler wants to merge 1 commit into
JohnCobbler wants to merge 1 commit into
Conversation
…ats#121) A range whose length overflows (e.g. typemin(Int):typemax(Int)) reports length 0 while not being empty, so it passed the isempty guard in _quantilesort! and then tripped an internal '@Assert n > 0' in _quantile. Add a length-0 guard that throws an informative ArgumentError, and turn the now-redundant assertion into a defensive ArgumentError so the check also holds under --check-bounds=no. Co-authored-by: Claude <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #206 +/- ##
=======================================
Coverage 96.43% 96.44%
=======================================
Files 2 2
Lines 449 450 +1
=======================================
+ Hits 433 434 +1
Misses 16 16 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Give
quantile!a clearArgumentErrorinstead of an internalAssertionErrorfor a data vector that reports
length 0while not being empty, fixing #121.An integer range whose length overflows (e.g.
typemin(Int):typemax(Int)) haslength == 0butisempty == false. Such input passes theisemptyguard in_quantilesort!and then trips@assert n > 0inside_quantile, whose commentclaims the case "should never happen here".
This adds a
length(v) == 0guard in_quantilesort!(covering bothquantile!entry points before any
_quantilecall) that throws anArgumentErrorpointingthe user at the overflow and suggesting they collect to a concrete vector first.
The now-redundant
@assertin_quantilebecomes a defensiveArgumentError,which also keeps the check under
--check-bounds=nowhere@assertmay be elided.The default
quantile(r, 0.5)path is unchanged: it materializes the range viaBase.copymutablefirst, which errors before reaching this code; that is aseparate, appropriate failure for a range claiming 2^64 elements.
Tests cover both overflow paths and confirm the existing empty-vector behavior
(
ArgumentError("empty data vector")) still fires.