Repository navigation
fix(core,syntax): compute on stored values, not on the print format - #5
Merged
kobaltgit merged 1 commit intoNov 20, 2026
Merged
Conversation
Procedures read numeric cells through `DataSet::get_cell_display` and parsed the formatted string back to f64. Numeric CSV columns get a two-decimal print format, so every procedure computed on values rounded to 2 dp (0.123456 was read as 0.12). As in SPSS, a print format governs display only. Add `DataSet::get_cell_numeric`, which returns the stored value with the same missing-value handling (Null, empty, ".", "NA"), and use it at the 30 sites that parsed the display string as a number (DESCRIPTIVES, REGRESSION, CORRELATIONS, PARTIAL CORR, t-tests, ANOVA, GLM, nonparametric, FACTOR, RELIABILITY, CURVEFIT, logistic and multinomial regression, MEANS, SELECT IF). Sites that use the display string as a group key or to match text are unchanged. Tests: numeric_precision_tests.rs on exactly linear data (y = 2x + 0.001, three decimals): mean, slope, intercept and r are exact to 1e-9; three of the four fail before this change. Co-Authored-By: jjohare <github@thedreamlab.uk>
Owner
|
Thank you so much for this PR! This fixes a critical precision issue across the entire engine, and the implementation is clean, robust, and well-tested. Regarding the scope:
Feel free to either include those two GUI dialog sites if you'd like, or simply mark the PR as Ready for review as-is and we'll happily merge it and handle the GUI parts in a follow-up commit! |
kobaltgit
marked this pull request as ready for review
November 20, 2026 18:52
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.
Problem
Procedures read numeric cells through
DataSet::get_cell_displayand parse the formatted string back tof64. Numeric CSV columns are given a two-decimal print format (F8.2), so every procedure computes on values rounded to two decimal places.Reproduction (
statcraft-run, or any frontend overstatcraft_syntax):DESCRIPTIVES /VARIABLES=a /STATISTICS=MIN.reports a minimum of 0.12. On an exactly linear pair with three decimals (y = 2x + 0.001),CORRELATIONSgives r = 0.99995 instead of 1, andREGRESSIONgives a slope and intercept that differ from numpy's in the fourth significant figure.As in SPSS, a print format should govern display only; it should never change what a procedure computes. The same path affects
.savfiles whose variables carry a short format.Change
DataSet::get_cell_numeric(row, col) -> Option<f64>returns the stored value, with the same missing-value handling the call sites used (Null, and text cells that are empty,.orNA).Tests
crates/statcraft_syntax/tests/numeric_precision_tests.rs, on exactly linear data with three decimals: mean, minimum, slope, intercept and r are exact to 1e-9. Three of the four tests fail without the change (the fourth checks that display formatting is unchanged).Ran locally with
-j 1as AGENTS.md asks:cargo fmt --all -- --check;cargo clippy -p statcraft_core -p statcraft_io -p statcraft_algo -p statcraft_syntax --all-targets -- -D warnings;cargo teston the same four crates, 495 passed, 0 failed. The GUI crates were not built here.Opened as a draft for your review; happy to adjust the scope, for example to cover the grouping sites as well.
🤖 Generated by Claude Code