fix(scoring): parse underscores in the fractional part of upstream constants - #993
Conversation
…nstants The JSONbored#969 constant parser added underscore support for the integer part and exponents, but the fractional digit classes (\d* / \.\d+) still rejected '_'. Per PEP 515 underscores are valid between digits in any part, so a valid upstream literal like 0.000_001 matched only '0.000' and was read as 0 — a silent truncation (and divide/multiply-by-zero hazard) that skews every score preview/breakdown. Allow '_' in the fractional digits too; Number() already strips them before parsing. Existing integer-underscore/exponent cases are unchanged. Closes JSONbored#992
|
Note Gittensory Gate skippedPR closed before full evaluation. No late first comment was created.
💰 Earn for open-source contributions like this. Gittensor lets GitHub contributors earn for the work they already do — register to start earning →. Checked by Gittensory, a quiet PR intelligence layer for OSS maintainers. |
|
Superagent didn't find any vulnerabilities or security issues in this PR. |
Codecov Report✅ All modified and coverable lines are covered by tests.
Additional details and impacted files@@ Coverage Diff @@
## main #993 +/- ##
===========================================
- Coverage 96.61% 70.01% -26.60%
===========================================
Files 110 110
Lines 15079 15079
Branches 5451 5451
===========================================
- Hits 14569 10558 -4011
- Misses 106 3231 +3125
- Partials 404 1290 +886 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
🟥🟥🟥🟥🟥🟥🟥🟥🟥🟥🟥🟥🟥🟥🟥🟥🟥🟥 ⛔ Maintainer review — Blockers foundReviewed 2 changed file(s) — two independent AI reviewers, synthesized.
Merge readiness: ❌ CI is red — approval withheld until it's green. Failing: see the checks tab. Summary The change fixes a parsing bug by updating the regex in 🛑 Hard blockers — must fix before merge
💡 Nits — non-blocking, optional
This repo uses one-shot review: a rejected PR is closed, not iterated in place. Address the above and open a new focused PR. |
Summary
#969 ("parse underscore separators and scientific notation in upstream constants") fixed the Python-numeric-literal parser for the integer part (
1_500_000) and exponents (1e-9) — but left the fractional part underscore-blind. Per PEP 515, underscores are valid between digits in any part of a numeric literal, including after the decimal point. So a valid upstream constant like0.000_001matches only up to the first fractional underscore and is read as0— a silent truncation that turns a small rate/share into zero (a divide/multiply-by-zero hazard that skews every score preview/breakdown).Verified by running the exact merged regex +
Number(raw.replace(/_/g, "")):0.000_0013.14_151_000.000_5(Integer grouping and exponents parse correctly — only fractional grouping was broken.)
Reachable:
refreshScoringModelSnapshotfetches upstreamgittensor/constants.pyand runs it through this parser into the scoringconstantsthat feedbuildScorePreview/ the score breakdown / unmodeled-constant detection.Fix
Allow
_in the fractional digit classes too (and require a leading digit in the bare-decimal branch), mirroring the integer part.Number(raw.replace(/_/g, ""))already strips the underscores, so no other change is needed:Verified to parse
0.000_001/3.14_15/1_000.000_5correctly and leave every previously-passing case unchanged (1_500_000,5.8e1,1e-9,-2.5e-3,0.90,1.15,.5,5).Tests
Added a regression test asserting the fractional-underscore literals parse to their true values (the #969 test covered only integer underscores + exponents + a plain
0.90, so the truncation shipped green). Scoring suite green locally (43 passed);tscclean.Closes #992