fix(lib): emit p-value columns in scientific notation again - #102
Open
SkyeAv wants to merge 1 commit into
Open
Conversation
The KGX-compliance rework (#71) made format_numeric() emit p_value / adjusted_p_value as real JSON numbers because numeric_slot_kind reports the float-typed Biolink slots -- silently retiring the {:.4e} branch for exactly the columns it existed for, so edges shipped shortest-repr numbers ("p_value":0.0001) instead of the controlled notation the tutorial documents ("p_value":"1.0000e-03"). P-value-like columns are now always formatted as scientific-notation strings ahead of the numeric-slot short-circuit. Biolink validation runs in Pydantic's lax mode, which coerces the numeric string back, so validate-kgx stays green (pinned by a new record in the validate_kgx test). Non-p-value numeric columns keep the model-typed behavior: a real JSON number once a future biolink-model types the slot, {:.4g} strings until then.
|
Important Review available on request
Reviews should be triggered manually for repositories with fewer than 10 stars. Select Trigger review above or comment ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Restores the controlled scientific-notation output for p-value columns: the KGX-compliance rework (#71) switched
format_numeric()to real JSON numbers forp_value/adjusted_p_value, silently retiring the{:.4e}branch for exactly the columns it existed for — edges shipped"p_value":0.0001instead of the documented"p_value":"1.0000e-03".What was broken
format_numeric()consultednumeric_slot_kind()first, which reports"float"forp_value/adjusted_p_value(declaredOptional[float]on the baseAssociationclass in the pinnedbiolink-model), so the float-kind arm short-circuited with a cast-only path. The{:.4e}formatting could only fire for p-value columns without a numeric slot — which don't exist.0.0001,0.05,6.52e-6) instead of controlled four-significant-figure scientific notation.Fix
src/tablassert/lib.py: any p-value-like column (same substring match asnumeric_columns) is now formatted{:.4e}before the numeric-slot short-circuit; branch ordering is the guard. Non-p-value numeric columns (effect_size,supporting_study_size) keep the model-typed behavior: a real JSON number once a futurebiolink-modeltypes the slot (#1770/#1774), controlled{:.4g}strings until then.validate_record()/validate_kgx()validate in Pydantic lax mode, which coerces the numeric string back for thefloatslot — verified empirically against the pinned model classes before choosing this fix.Tests
tests/test_biolink.py: thevalidate_kgxmatrix gains an edge with"p_value":"1.0000e-03"that must count as fully valid (while"not-a-number"still fails).tests/test_lib.py: p-value formatting tests assert scientific-notation strings; the null-stripping test pins a zero p-value survivingstrip_nullsas"0.0000e+00".tests/test_e2e_smoke.py: the real-pipeline coercion smoke asserts"p_value" == "1.0000e-02"on the emitted edge.Docs
docs/tutorial.md: the example edge output is accurate again — including dropping the flatsupporting_study_sizethat never reaches the edge onbiolink-model4.4.3 (it rides the inlined supporting study).CHANGELOG.md:Unreleased / Fixedentry documenting the regression and restoration;format_numeric()/numeric_slot_kind()docstrings updated.Risks / caveats
validate-kgx, the agent self-audit) stays green; a hypothetical strict-mode downstream consumer would coerce the string.Testing
uv run ruff check .→ clean;uv run ruff format --check .→ clean;uv run pyright→0 errors, 0 warnings.uv run pytest -q→898 passed, 35 skipped(identical count to pristinemain).