Repository navigation
Fix TDIGEST returning nan for a sketch with a single observation - #1035
Merged
gabsow merged 2 commits intoAug 2, 2026
Merged
Conversation
PerumalsamyR
force-pushed
the
fix-tdigest-single-observation-nan
branch
from
July 15, 2026 06:42
e024878 to
45bc5a5
Compare
gabsow
previously approved these changes
Aug 2, 2026
Collaborator
|
Thank you very much; it's a real fix that wasn't pinned to Bloom yet. |
…isBloom#870) Bump deps/t-digest-c to 50edef3, which fixes td_compress bailing out on total_weight <= 1 before promoting the sole unmerged node to a merged centroid. The sketch then looked empty to the query paths, so TDIGEST.QUANTILE, TDIGEST.CDF and TDIGEST.TRIMMED_MEAN replied nan for a sketch holding exactly one weight-1 observation. Add a flow regression test covering all three commands.
gabsow
force-pushed
the
fix-tdigest-single-observation-nan
branch
from
August 2, 2026 08:28
45bc5a5 to
b522bfe
Compare
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1035 +/- ##
==========================================
- Coverage 82.71% 82.68% -0.04%
==========================================
Files 21 21
Lines 3275 3275
==========================================
- Hits 2709 2708 -1
- Misses 566 567 +1 🚀 New features to boost your workflow:
|
AvivDavid23
enabled auto-merge (squash)
August 2, 2026 11:14
gabsow
disabled auto-merge
August 2, 2026 11:27
gabsow
approved these changes
Aug 2, 2026
4 tasks
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.



Fixes #870
Problem
A t-digest sketch holding exactly one weight-1 observation replies
nanon every query command:TDIGEST.CDFandTDIGEST.TRIMMED_MEANare affected the same way. The behavior is inconsistent rather than intentional: adding the same value twice, or a single observation with weight 2, returns the correct result — only the single weight-1 sample case fails.Root cause
In
deps/t-digest-c,td_compress()has an early returnif (total_weight <= 1)(introduced upstream in43fe4beto guard thelog(total_weight)denominator against division by zero). It returns before promoting the unmerged node to a merged centroid, somerged_nodesstays 0 and every query path takes its "empty histogram → nan" branch. The library's dedicated single-centroid handling intd_quantile/td_quantiles("with one data point, all quantiles lead to Rome") was unreachable for this case.This was fixed upstream in RedisBloom/t-digest-c@50edef3 (MOD-13821), but the submodule here is still pinned one commit behind (
5b89d70), so the module still ships the bug.Fix
deps/t-digest-csubmodule from5b89d70to50edef3(single-commit bump; the only change is thetd_compressfix).test_tdigest_single_observation) coveringTDIGEST.QUANTILE,TDIGEST.CDF, andTDIGEST.TRIMMED_MEANon a single-observation sketch, since the upstream fix landed without test coverage.Testing
Built the module and ran the full tdigest flow suite locally (macOS arm64, Redis 8):
Verified the exact repro from #870 now returns the observation value:
Note
Low Risk
Behavior change is limited to the edge case of one observation in t-digest queries; CI change only gates S3 uploads on fork PRs.
Overview
Fixes TDIGEST returning
nanwhen a sketch has exactly one weight-1 observation (issue #870), by picking up the upstreamdeps/t-digest-cfix wheretd_compress()no longer bails out before promoting that lone point into a merged centroid.Adds flow regression
test_tdigest_single_observation, assertingTDIGEST.QUANTILE,TDIGEST.CDF, andTDIGEST.TRIMMED_MEANall return sensible values for a single added value.CI: Linux and macOS flow workflows now skip S3 artifact upload on pull requests from forks (
github.event.pull_request.head.repo.fork), so untrusted PRs do not run steps that use AWS credentials.Reviewed by Cursor Bugbot for commit b522bfe. Bugbot is set up for automated code reviews on this repo. Configure here.