Repository navigation
Conversation
Owner
|
Folded into #609 (see the PR description for credit). Thanks for the report and the repro. |
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.
The change
Stats.modebreaks ties by first appearance, but computing a sorted statistic first can change the answer:With the default
use_copy=True, lazy sorting reordersself.databeforemodecounts it. The fix keeps that data in its original order and caches a separate sorted view.clear_cache()discards the view, andmedian_abs_devreuses it. No-copy and presorted behavior stay unchanged; trimming still replaces the data and clears the caches.The sorted view retains an additional list of references after first use, without copying the numeric objects. This avoids repeatedly sorting the original data. Callers modifying
stats.datamust callclear_cache(), as documented; this now also applies to uncached quantile queries on copied data.Tests cover call order, cache refresh, trimming, no-copy and presorted inputs, and unhashable numeric values:
tox -e py314environment: 700 passed. Other tox environments were not run.The backstory
This is my first contribution to Boltons. It came from an AI-assisted search for useful, focused correctness fixes, not a production incident or prior use of the library. Comparing ordinary public API calls in different orders exposed the mismatch with the documented mode tie-breaking rule.
AI assistance
The code, tests, and description were prepared with AI assistance. No personal production experience is claimed above.
User request and relevant implementation/review prompts
User continuation:
在搞3个("do another three", continuing a request to find, implement, test, review, and submit useful PRs).Delegated research instruction:
Refinement after the first implementation caused a measured sorting regression:
Relevant excerpts from the independent review prompt: