fix(tdigest): preserve stored min and max when merging - #525
Merged
Merged
Conversation
Merging a digest whose extreme centroids have weight greater than one re-derived min and max from those centroid means. Copy the stored extrema from the other digest first so rank and quantile tail interpolation stay correct, especially for deserialized images.
leerho
approved these changes
Sep 17, 2026
leerho
left a comment
Member
There was a problem hiding this comment.
Thank you for finding and fixing this!
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.
Summary
min_/max_from the other digest intdigest::mergebefore compressing the combined centroid list.Why
mergepreviously re-derived extrema from the extreme centroid means. That is exact only when those centroids have unit weight. Deserialized images (and the reference implementation format) can have weighted tails, so min/max drifted inward and rank/quantile tail interpolation used the wrong endpoints.Same defect as apache/datasketches-rust#277.
Validation
tdigest_testincludingmerge preserves deserialized min max with weighted tailsand the full[tdigest]suite (49 cases).