Skip to content

Commit 270b6d3

Browse files
Address review: drop defensive extras, fix SQLFluff annotate perms
Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 2a93127 commit 270b6d3

10 files changed

Lines changed: 23 additions & 87 deletions

File tree

.github/workflows/lint_sqlfluff.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ on:
66
jobs:
77
lint-mimic-iv:
88
runs-on: ubuntu-latest
9+
permissions:
10+
contents: read
11+
checks: write
912
steps:
1013
- name: checkout
1114
uses: actions/checkout@v7
@@ -35,12 +38,10 @@ jobs:
3538
shell: bash
3639
run: sqlfluff lint --format github-annotation --annotation-level failure --nofail ${{ steps.get_files_to_lint.outputs.lintees }} > annotations.json
3740
- name: Annotate
38-
# Fork PRs cannot create check runs with GITHUB_TOKEN; lint already ran.
39-
continue-on-error: true
4041
if: steps.get_files_to_lint.outputs.lintees != ''
4142
uses: yuzutech/annotations-action@v0.6.0
4243
with:
4344
repo-token: "${{ secrets.GITHUB_TOKEN }}"
4445
title: "SQLFluff Lint"
4546
input: "./annotations.json"
46-
ignore-missing-file: true
47+
ignore-unauthorized-error: true

mimic-iii/buildmimic/duckdb/import_duckdb.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ usage () {
2929
die "
3030
USAGE: ./import_duckdb.sh mimic_data_dir [output_db]
3131
WHERE:
32-
mimic_data_dir directory that contains csv.tar.gz or csv files
32+
mimic_data_dir directory that contains csv.gz or csv files
3333
output_db: optional filename for duckdb file (default: mimic3.db)\
3434
"
3535
}

mimic-iii/buildmimic/postgres/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ concepts:
281281
@echo '---------------------'
282282
@echo ''
283283
@sleep 2
284-
cd ../../concepts/ && psql "$(DBSTRING)" -v ON_ERROR_STOP=1 -f make-concepts.sql
284+
cd ../../concepts_postgres/ && psql "$(DBSTRING)" -v ON_ERROR_STOP=1 -c "CREATE SCHEMA IF NOT EXISTS mimiciii_derived;" -f postgres-make-concepts.sql
285285

286286

287287
.PHONY: help mimic clean

mimic-iii/buildmimic/sqlite/import.py

Lines changed: 2 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -10,34 +10,6 @@
1010
CHUNKSIZE = 10 ** 6
1111
CONNECTION_STRING = "sqlite:///{}".format(DATABASE_NAME)
1212

13-
# Column dtypes for tables that trigger pandas mixed-type warnings when
14-
# loaded with the default low_memory chunked inference (see #1237).
15-
# Types mirror mimic-iii/buildmimic/postgres/postgres_create_tables.sql.
16-
TABLE_DTYPES = {
17-
"chartevents": {
18-
"WARNING": "Int64",
19-
"ERROR": "Int64",
20-
"RESULTSTATUS": "string",
21-
"STOPPED": "string",
22-
},
23-
"datetimeevents": {
24-
"WARNING": "Int64",
25-
"ERROR": "Int64",
26-
"RESULTSTATUS": "string",
27-
"STOPPED": "string",
28-
},
29-
"inputevents_cv": {
30-
"ORIGINALRATE": "float64",
31-
"ORIGINALRATEUOM": "string",
32-
"ORIGINALSITE": "string",
33-
},
34-
"noteevents": {
35-
"CHARTTIME": "string",
36-
"STORETIME": "string",
37-
"ISERROR": "string",
38-
},
39-
}
40-
4113

4214
def _table_name_from_csv(filename: str) -> str:
4315
"""Derive SQL table name from a CSV path (literal suffix, not str.strip)."""
@@ -49,18 +21,6 @@ def _table_name_from_csv(filename: str) -> str:
4921
return name.lower()
5022

5123

52-
def _read_csv(path, table, **kwargs):
53-
# low_memory=False avoids dtype re-inference across chunks; table-specific
54-
# dtypes pin the columns that otherwise flip between numeric/object.
55-
return pd.read_csv(
56-
path,
57-
index_col="ROW_ID",
58-
low_memory=False,
59-
dtype=TABLE_DTYPES.get(table),
60-
**kwargs,
61-
)
62-
63-
6424
if os.path.exists(DATABASE_NAME):
6525
msg = "File {} already exists.".format(DATABASE_NAME)
6626
print(msg)
@@ -77,11 +37,11 @@ def _read_csv(path, table, **kwargs):
7737
for table, f in sorted(files_by_table.items()):
7838
print("Starting processing {}".format(f))
7939
if os.path.getsize(f) < THRESHOLD_SIZE:
80-
df = _read_csv(f, table)
40+
df = pd.read_csv(f, index_col="ROW_ID")
8141
df.to_sql(table, CONNECTION_STRING)
8242
else:
8343
# If the file is too large, let's do the work in chunks
84-
for chunk in _read_csv(f, table, chunksize=CHUNKSIZE):
44+
for chunk in pd.read_csv(f, index_col="ROW_ID", chunksize=CHUNKSIZE):
8545
chunk.to_sql(table, CONNECTION_STRING, if_exists="append")
8646
print("Finished processing {}".format(f))
8747

mimic-iii/concepts_duckdb/demographics/icustay_hours.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ WITH all_hours AS (
44
SELECT
55
it.icustay_id,
66
STRPTIME(STRFTIME(CAST(it.intime_hr + INTERVAL '59' MINUTE AS TIMESTAMP), '%Y-%m-%d %H:00:00'), '%Y-%m-%d %H:00:00') AS endtime,
7-
(SELECT list(g) FROM generate_series(-24, CAST(CEIL(DATE_DIFF('HOUR', it.intime_hr, it.outtime_hr)) AS BIGINT)) AS t(g)) AS hrs
7+
GENERATE_SERIES(-24, CAST(CEIL(DATE_DIFF('HOUR', it.intime_hr, it.outtime_hr)) AS BIGINT)) AS hrs
88
FROM mimiciii_derived.icustay_times AS it
99
)
1010
SELECT

mimic-iv-cxr/txt/chexpert/run_chexpert_on_files.sh

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,12 @@ fi
2222
sleep 2
2323

2424
# loop through each .csv file in the section folder
25-
for fn_path in "$REPORT_PATH"/*.csv; do
26-
[ -f "$fn_path" ] || continue
27-
fn=$(basename "$fn_path")
25+
for fn in "$REPORT_PATH"/*; do
26+
fn=${fn##*/}
2827
echo "$(date): $fn"
29-
fn_stem=${fn%.csv}
28+
fn_stem=$(echo "$fn" | cut -d. -f 1)
3029
# run chexpert - must be run from chexpert folder
31-
python "$CHEXPERT_PATH/label.py" --verbose \
32-
--reports_path "$fn_path" \
33-
--output_path "${fn_stem}_labeled.csv" \
34-
--mention_phrases_dir "$CHEXPERT_PATH/phrases/mention" \
35-
--unmention_phrases_dir "$CHEXPERT_PATH/phrases/unmention" \
36-
--pre_negation_uncertainty_path "$CHEXPERT_PATH/patterns/pre_negation_uncertainty.txt" \
37-
--negation_path "$CHEXPERT_PATH/patterns/negation.txt" \
38-
--post_negation_uncertainty_path "$CHEXPERT_PATH/patterns/post_negation_uncertainty.txt"
30+
python "$CHEXPERT_PATH/label.py" --verbose --reports_path "$REPORT_PATH/$fn" --output_path "${fn_stem}_labeled.csv" --mention_phrases_dir "$CHEXPERT_PATH/phrases/mention" --unmention_phrases_dir "$CHEXPERT_PATH/phrases/unmention" --pre_negation_uncertainty_path "$CHEXPERT_PATH/patterns/pre_negation_uncertainty.txt" --negation_path "$CHEXPERT_PATH/patterns/negation.txt" --post_negation_uncertainty_path "$CHEXPERT_PATH/patterns/post_negation_uncertainty.txt"
3931
echo "$(date): done!"
4032
echo ''
41-
done
33+
done

mimic-iv-cxr/txt/negbio/run_negbio.sh

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,20 @@ sleep 2
3232
# mimic_cxr_001.csv
3333
# mimic_cxr_002.csv
3434
# .. etc
35-
for fn_path in "$BASE_FOLDER"/mimic_cxr_*.csv;
35+
for fn in "$BASE_FOLDER"/*;
3636
do
37-
[ -f "$fn_path" ] || continue
38-
fn=$(basename "$fn_path")
37+
fn=${fn##*/}
3938
echo "Looping through files with mimic_cxr_###.csv pattern."
4039
# validate it's a mimic_cxr sections file
41-
if [[ "$fn" =~ ^mimic_cxr_[0-9]+\.csv$ ]];
40+
if [[ $fn =~ ^mimic_cxr_[0-9]+.csv$ ]];
4241
then
43-
export INPUT_FILE="$fn_path"
42+
export INPUT_FILE=${BASE_FOLDER}/$fn
4443
# remove extension from filename
4544
# sets the folder location to stem of original filename
4645
# all intermediate files will be saved in this folder
47-
export OUTPUT_DIR="${INPUT_FILE%.csv}"
46+
export OUTPUT_DIR=${INPUT_FILE::-4}
4847

49-
echo "$OUTPUT_DIR - running NegBio.."
48+
echo "$OUTPUT_DIR" - running NegBio..
5049
python "$NEGBIO_PATH/negbio/negbio_csv2bioc.py" --output "$OUTPUT_DIR/report" "$INPUT_FILE"
5150
python "$NEGBIO_PATH/negbio/negbio_pipeline.py" section_split --pattern "$NEGBIO_PATH/patterns/section_titles_cxr8.txt" --output "$OUTPUT_DIR/sections" "$OUTPUT_DIR"/report/* --workers=6
5251
python "$NEGBIO_PATH/negbio/negbio_pipeline.py" ssplit --output "$OUTPUT_DIR/ssplit" "$OUTPUT_DIR"/sections/* --workers=6
@@ -56,7 +55,7 @@ do
5655
python "$NEGBIO_PATH/negbio/negbio_pipeline.py" neg2 --output "$OUTPUT_DIR/neg" --pre-negation-uncertainty-patterns "$NEGBIO_PATH/patterns/chexpert_pre_negation_uncertainty.yml" --neg-patterns "$NEGBIO_PATH/patterns/neg_patterns2.yml" --post-negation-uncertainty-patterns "$NEGBIO_PATH/patterns/post_negation_uncertainty.yml" --neg-regex-patterns "$NEGBIO_PATH/patterns/neg_regex_patterns.yml" --uncertainty-regex-patterns "$NEGBIO_PATH/patterns/uncertainty_regex_patterns.yml" "$OUTPUT_DIR"/dner/* --workers=6
5756

5857
# ultimate filename we save the labels to
59-
export OUTPUT_LABELS="$OUTPUT_DIR/${fn%.csv}_labels.csv"
58+
export OUTPUT_LABELS=$OUTPUT_DIR/${fn::-4}_labels.csv
6059
python "$NEGBIO_PATH/negbio/ext/chexpert_collect_labels.py" --phrases_file "$NEGBIO_PATH/patterns/chexpert_phrases.yml" --output "$OUTPUT_LABELS" "$OUTPUT_DIR"/neg/*
6160
fi
6261
done

mimic-iv/concepts/validate_concepts.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ fail=0
3232
missing=0
3333
while read -r tbl; do
3434
[ -z "${tbl}" ] && continue
35-
# exact field match (regex grep can false-hit prefixes)
36-
if ! awk -F, -v t="${tbl}" '$1 == t { found=1 } END { exit !found }' <<< "${ACTUAL}"; then
35+
if ! grep -q "^${tbl}," <<< "${ACTUAL}"; then
3736
echo "MISSING: expected table ${DATASET}.${tbl} was not built"
3837
missing=1
3938
fail=1
@@ -48,7 +47,7 @@ empty=0
4847
while IFS=, read -r tbl rows; do
4948
[ -z "${tbl}" ] && continue
5049
# only validate the tables we actually build (ignore _metadata and any strays)
51-
if grep -Fxq "${tbl}" <<< "${EXPECTED}" && [ "${rows:-}" -eq 0 ]; then
50+
if grep -qx "${tbl}" <<< "${EXPECTED}" && [ "${rows}" -eq 0 ]; then
5251
echo "EMPTY: table ${DATASET}.${tbl} has 0 rows"
5352
empty=1
5453
fail=1

src/mimic_utils/sqlglot_dialects/duckdb.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@
33
- ``NUMERIC`` is ``DECIMAL(38, 9)``, but DuckDB's bare ``DECIMAL`` defaults
44
to ``DECIMAL(18, 3)``, which silently rounds values to three decimal places
55
(e.g. ``CAST(0.0255 AS NUMERIC)`` becomes ``0.026`` before any explicit ``ROUND``).
6-
- ``GENERATE_ARRAY`` must remain a LIST (for later ``UNNEST``). Native sqlglot
7-
emits ``GENERATE_SERIES``, which is a set-returning function; wrapping as a
8-
list matches Postgres ``ARRAY(GENERATE_SERIES)`` and keeps ``UNNEST(hrs)``
9-
reliable across DuckDB versions (#1736).
106
"""
117
import re
128

@@ -45,13 +41,6 @@ def _parse_datetime_sql(self: DuckDB.Generator, expression: exp.ParseDatetime) -
4541
return f"STRPTIME({this}, {fmt})"
4642

4743

48-
# GENERATE_ARRAY(a, b) -> list via generate_series (inclusive), for UNNEST.
49-
def _generate_array_sql(self: DuckDB.Generator, expression: exp.Expression) -> str:
50-
start = self.sql(expression, "start")
51-
end = self.sql(expression, "end")
52-
return f"(SELECT list(g) FROM generate_series({start}, {end}) AS t(g))"
53-
54-
5544
class MimicDuckDB(DuckDB):
5645
class Generator(DuckDB.Generator):
5746
def datatype_sql(self, expression: exp.DataType) -> str:
@@ -65,5 +54,4 @@ def datatype_sql(self, expression: exp.DataType) -> str:
6554
**DuckDB.Generator.TRANSFORMS,
6655
exp.RegexpExtract: _regexp_extract_sql,
6756
exp.ParseDatetime: _parse_datetime_sql,
68-
exp.GenerateSeries: _generate_array_sql,
6957
}

tests/test_transpile.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,6 @@ def t(bq: str, dialect: str) -> str:
7474
# GENERATE_ARRAY -> ARRAY(SELECT ... GENERATE_SERIES) (postgres)
7575
("generate_array_pg", "SELECT GENERATE_ARRAY(-24, 5) AS hrs FROM t", "postgres",
7676
"SELECT ARRAY(SELECT * FROM GENERATE_SERIES(-24, 5)) AS hrs FROM t"),
77-
# GENERATE_ARRAY -> list via generate_series (duckdb); must stay list for UNNEST
78-
("generate_array_duckdb", "SELECT GENERATE_ARRAY(-24, 5) AS hrs FROM t", "duckdb",
79-
"SELECT (SELECT list(g) FROM generate_series(-24, 5) AS t(g)) AS hrs FROM t"),
8077

8178
# handled natively by sqlglot 30.x (regression guards)
8279
("datetime_date_pg", "SELECT DATETIME(me.chartdate) FROM t me", "postgres",

0 commit comments

Comments
 (0)