Throw a clear error for degenerate-length data vectors (fixes #121) - #206
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.43%
=======================================
Files 2 2
Lines 449 449
=======================================
Hits 433 433
Misses 16 16 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
| "integer range whose length overflows (e.g. `typemin(Int):typemax(Int)`) — " * | ||
| "collect it to a concrete vector first")) |
There was a problem hiding this comment.
I believe that such a vector would take up 148 exabytes, so probably not the right recommendation.
|
Agreed. 148 exabytes is not a useful suggestion. The message says the length doesn't fit in Int, and asks for a collection whose length does. |
The example range is enormous. Point the caller at a collection whose length fits in Int.
|
Thanks! Though I have the impression that printing a specific message for this particular range is overkill. There are probably many places in Statistics, and other JuliaStats packages where we would have to do the same. Yet it seems very unlikely that people would use such a range in practice. So while being correct is of course a requirement, providing a nice error message doesn't seem super important. How about just replacing the |
|
Fair point. The guard is |
An overflowing range reports length 0. It now gets the same empty-vector error. No separate message.
|
Thanks! |
quantile!throwsArgumentError("empty data vector")whenlengthis 0. Fixes #121.typemin(Int):typemax(Int)reportslength0.isemptyis false, so the old emptiness check let it through to@assert n > 0. The guard islength(v) == 0.quantile(r, 0.5)withsorted=falsestill errors inBase.copymutable.