Repository navigation
Conversation
This was referenced Oct 12, 2026
Wkhanex
reviewed
Oct 14, 2026
Wkhanex
left a comment
There was a problem hiding this comment.
Appending out-of-order values and calling clear_cache() now agrees with Python's statistics results. I checked successive appends with both copy modes, including a new negative minimum: median, mean, minimum and maximum are all recomputed.
Checked cb330b389ef5 with standalone Python 3.12.14 checks (24 passing assertions). I haven't run the full upstream suite.
This branch has not been deployed
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.clear_cache()now discards theis_sortedhint as well as cached measures. Its documented use after modifyingStats.datacould otherwise recompute incorrect values from an order that no longer holds:Reset the hint when clearing the cache, document that behavior, and cover repeated mutations with both copy modes. The
is_sorted=Trueoptimization remains available until the caller invalidates the cache.The regression failed on master. After the fix,
python -m pytest --doctest-modules boltons tests -qpassed: 679 tests and 12 subtests on Python 3.12/Linux. Other platforms were not run locally.Related #534 preserves mode tie-breaking while computing sorted measures. That PR leaves
_is_sortedset afterclear_cache()too, so it does not fix this presorted-input mutation case. This change does not alter mode tie-breaking or introduce a sorted-data cache. Open/closed searches forclear_cache,is_sorted, and Stats cache found no matching fix.The backstory
Same contribution experiment and tooling as #569. While reading Stats' explicit mutation/cache contract, Codex reproduced wrong minimum, maximum, and median results after following the documented
clear_cache()advice. This is a locally constructed regression, not a production incident.AI assistance