Skip to content

Fix false matches in MIMIC concept comparisons - #2183

Open
haoyu-haoyu wants to merge 1 commit into
MIT-LCP:mainfrom
haoyu-haoyu:fix/concept-value-comparison
Open

haoyu-haoyu wants to merge 1 commit into
MIT-LCP:mainfrom
haoyu-haoyu:fix/concept-value-comparison

Conversation

@haoyu-haoyu

Copy link
Copy Markdown

Summary

I added 1 to one hadm_id in a copy of the MIMIC-IV Demo age table.
On main, compare_concepts still reported 275 rows OK. The default
relative tolerance was enough to treat the two admission IDs as equal.
The comparator also converted text codes to numbers, so "001" matched
"1". Even with --rtol 0 --atol 0, two different floats could match
because the comparison used values that had already been rounded for sorting.

This change compares integer IDs and text codes exactly, preserves nullable
BIGINT and DECIMAL values when reading from PostgreSQL and DuckDB, and
uses the original values for floating-point comparisons. If one engine
returns an integer and the other returns a float, the values must match
exactly.

Tests

  • All 65 derived tables in MIMIC-IV Demo 2.2 matched before and after.
    With one hadm_id changed in the 275-row age copy, the default command
    now exits 1 and reports hadm_id(1). I got the same result with
    PostgreSQL 16.2 and 17.12.
  • In a separate run, I changed one ID in each of the 64 nonempty tables.
    main flagged 5 tables. This branch flagged all 64 and named the changed
    ID column in each. Reversing the row and column order without changing
    any values still passed for all 65 tables.
  • With --rtol 0 --atol 0, 1.0 and 1.0000000004 now report a
    difference. With --rtol 0 --atol 1e-9, they still match.
  • I ran the same 24 comparator tests against both versions. Nine failed
    on main, and all 24 passed on this branch. They now run alongside the
    transpiler tests on pull requests. The combined command passed all 360
    tests locally on Python 3.10.
  • The full suite had 424 passes and one failure. main has the same
    SQLFluff failure at line 79 of mimic-iv/concepts/score/sirs.sql
    (81 characters, limit 80).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant