Skip to content

Commit 52767e1

Browse files
committed
mimic-iv/buildmimic/sqlite/import.py: replace strip()
`strip()` removes any of the given characters from both the start and end of a string: https://docs.python.org/3/library/stdtypes.html#str.strip For a filename "chartevents.csv.gz" the resulting tablename currently is "hartevent" where it should be "chartevents". 'chartevents'.strip('.gz').strip('.csv').lower() Instead, strip the suffixes manually to derive the tablename from the filename. Later, we could use `removesuffix()`, which is available from Python 3.9 onwards: https://docs.python.org/3/library/stdtypes.html#str.removesuffix
1 parent 14b9f5f commit 52767e1

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

mimic-iv/buildmimic/sqlite/import.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@
1717
for f in glob("**/*.csv*", recursive=True):
1818
print("Starting processing {}".format(f))
1919
folder, filename = os.path.split(f)
20-
tablename = filename.strip(".gz").strip(".csv").lower()
20+
tablename = filename.lower()
21+
if tablename.endswith('.gz'):
22+
tablename = tablename[:-3]
23+
if tablename.endswith('.csv'):
24+
tablename = tablename[:-4]
2125
if os.path.getsize(f) < THRESHOLD_SIZE:
2226
df = pd.read_csv(f)
2327
df.to_sql(tablename, CONNECTION_STRING)

0 commit comments

Comments
 (0)