Skip to content

Fix MIMIC-III sqlite import using str.strip instead of suffix removal#1989

Open
Chessing234 wants to merge 1 commit intoMIT-LCP:mainfrom
Chessing234:fix/sqlite-import-strip-suffix
Open

Fix MIMIC-III sqlite import using str.strip instead of suffix removal#1989
Chessing234 wants to merge 1 commit intoMIT-LCP:mainfrom
Chessing234:fix/sqlite-import-strip-suffix

Conversation

@Chessing234
Copy link
Copy Markdown

Bug

In `mimic-iii/buildmimic/sqlite/import.py`, the target table name is derived with:

```python
df.to_sql(f.strip(".csv.gz").lower(), CONNECTION_STRING)
```

Root cause

`str.strip(chars)` treats the argument as a set of characters to remove from both ends, not a literal suffix. With `".csv.gz"` the set is `{'.', 'c', 's', 'v', 'g', 'z'}`, so in addition to the suffix it also strips any trailing character that happens to be in that set.

MIMIC-III's official filenames are uppercase (`PATIENTS.csv.gz`), and the stripping halts at the first non-matching uppercase character, so the correct table name survives in the common path. But if a user has lowercase copies of the files (case-insensitive filesystems, archives re-packed with lowercase names), names like `services.csv.gz` become:

```python

"services.csv.gz".strip(".csv.gz")
'service'
```

The trailing `s` of `services` is silently eaten, and the table is created under the wrong name.

Fix

Replace `f.strip(".csv.gz")` with `f[: -len(".csv.gz")]` on both call sites. This removes exactly the known suffix and is compatible with Python 3.8 (no `str.removesuffix`).

In mimic-iii/buildmimic/sqlite/import.py, the table name was derived via
`f.strip(".csv.gz")`. `str.strip` treats the argument as a set of
characters to remove from both ends, not a suffix, so it also eats any
trailing '.', 'c', 's', 'v', 'g', or 'z' in the filename.

MIMIC-III's distributed filenames are uppercase (e.g. PATIENTS.csv.gz),
so in practice the stripping halts at the first uppercase character and
the correct table name survives. But if a user has lowercase copies of
the files (case-insensitive filesystems, archives re-packed with lower
case), `services.csv.gz`.strip(".csv.gz") returns "service" and the
table is created under the wrong name.

Replace with `f[: -len(".csv.gz")]` to remove exactly the suffix. This
matches the intent and keeps 3.8 compatibility (no removesuffix).
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