Skip to content

Sync tutorial notebooks with Colab and link example code in docs - #1259

Open
jhnwu3 wants to merge 1 commit into
masterfrom
docs/tutorials-sync
Open

jhnwu3 wants to merge 1 commit into
masterfrom
docs/tutorials-sync

Conversation

@jhnwu3

@jhnwu3 jhnwu3 commented Oct 1, 2026

Copy link
Copy Markdown
Collaborator

Re-lands #1256 on master. #1256 was merged into medcode/icd-mappings two minutes after that branch had already been squash-merged as #1257, so its changes never reached master. This is the same commit cherry-picked onto master, with identical content and no conflicts.

Changes

  • examples/tutorials/tutorial_pyhealth_medcode.ipynb: now matches the Colab version. Its ICD9CM → ICD10CM cell uses the icd-mappings backend from medcode: ICD-9 <-> ICD-10 translation and grouper vocabularies via icd-mappings #1257.
  • tutorial_pyhealth_data.ipynb, tutorial_pyhealth_trainer.ipynb: synced with Colab, replacing the removed dataset.patients with unique_patient_ids.
  • docs/tutorials.rst:
    • [Source] links to each tutorial notebook.
    • All 74 example filenames link to the real files, fixing wrong or renamed paths.
    • The readmission list-table is fixed, blob/main becomes blob/master, and the file has no docutils warnings.

Testing

🤖 Generated with Claude Code

- Sync tutorial_pyhealth_{data,trainer,medcode}.ipynb with the Colab
  versions linked from docs/tutorials.rst. The repo copies of data and
  trainer still used dataset.patients, which BaseDataset no longer has
  (it is unique_patient_ids). The medcode notebook's ICD9CM->ICD10CM
  cell relies on the icd-mappings backend added in the parent commits.
- docs/tutorials.rst: link each Colab tutorial to its source notebook,
  turn every example filename into a link to the real file (fixing
  wrong or renamed paths such as the EEG SparcNet and eICU scripts),
  fix the broken readmission list-table, and blob/main -> blob/master.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
@Logiquo Logiquo added the status: manual Pending maintainer's review label Oct 22, 2026
@Logiquo

Logiquo commented Oct 22, 2026

Copy link
Copy Markdown
Collaborator

/review

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI review: findings

This docs-and-notebooks PR re-lands the Colab sync for three tutorial notebooks and rewrites docs/tutorials.rst so every example entry links to a [Source] file. I checked that every linked example and tutorial path exists in the tree, and that the APIs the notebooks now call (unique_patient_ids, get_patient, global_event_df with an event_type column) exist in pyhealth/datasets/base_dataset.py and pyhealth/data/data.py. The medcode notebook already uses CrossMap.load("ICD9CM", "ICD10CM") from #1257, and the old dataset.patients attribute is gone, so the notebook fix is needed. Blocking: docs/tutorials.rst changes the datasets_overview link from blob/main to blob/master, and about 80 links now depend on a master branch. The environment reports main as the main branch and the clone has no refs to confirm master holds these files, so the links could 404. Non-blocking: the data notebook hardcodes unverified dataset counts in a comment, and the medcode notebook adds an unrelated sorted() change. No public API, base class, or core code changes, and no tests are expected for notebook content. Overall risk is low once the branch-name question is settled. Redundancy: none.

Reviewed commit 7935b8e

Comment thread docs/tutorials.rst
=======================

For information on how to access and download the datasets supported by PyHealth, please refer to our `Datasets Overview Notebook <https://github.com/sunlabuiuc/PyHealth/blob/main/examples/datasets_overview.ipynb>`_.
For information on how to access and download the datasets supported by PyHealth, please refer to our `Datasets Overview Notebook <https://github.com/sunlabuiuc/PyHealth/blob/master/examples/datasets_overview.ipynb>`_.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[medium] Links switched from blob/main to blob/master without confirming master exists

The datasets_overview link changes from blob/main to blob/master, and all new [Source] and example links use blob/master too. The environment reports 'main' as the repository's main branch, and the local clone has no refs to show that a master branch exists or carries these files. If master is not the GitHub default or does not contain these paths, roughly 80 links in this file return 404. Confirm on GitHub that master contains examples/tutorials/*.ipynb and the example scripts, or revert to main, which the original link used.

"outputs": []
"metadata": {},
"outputs": [],
"source": "from pyhealth.datasets import MIMIC3Dataset\nimport polars as pl\n\nroot = \"https://storage.googleapis.com/pyhealth/Synthetic_MIMIC-III\"\n\ndataset = MIMIC3Dataset(\n root=root,\n dataset_name=\"mimic3\",\n tables=[\n \"diagnoses_icd\", # ICD-9 diagnosis codes per admission\n \"prescriptions\", # medication orders\n \"noteevents\", # clinical notes\n ],\n)\n\nprint(f\"Loaded {len(dataset.unique_patient_ids)} patients\")\n\n# Pick a patient who actually has events from all three tables, so every query\n# below returns something. Notes are sparse in this synthetic set (~1k notes\n# across ~50k patients), so patient 0 almost certainly has none.\npatient_ids_with_notes = (\n dataset.global_event_df\n .filter(pl.col(\"event_type\") == \"noteevents\")\n .select(\"patient_id\")\n .collect()[\"patient_id\"]\n .unique()\n)\npatient_id = patient_ids_with_notes[0]\npatient = dataset.get_patient(patient_id)\n\nprint(f\"\\nPatient ID: {patient.patient_id}\")\nprint(f\"Event types present: {list(patient.event_type_partitions.keys())}\")\nprint(f\"Total events: {len(patient.get_events())}\")"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[low] Hardcoded dataset statistics in code comment are unverified

The comment in the patient-selection cell says notes are sparse, with '~1k notes across ~50k patients', and that patient 0 'almost certainly has none'. Neither figure is checked in this PR. Remove the numbers or compute them in the notebook. Note also that unique() on the note patient IDs is unordered, so picking index 0 is not deterministic across runs.

"metadata": {},
"outputs": [],
"source": "# Pattern 2: Translate a patient's ICD-9 code list to CCS before modeling\n# This dramatically reduces vocabulary size.\n\ndef translate_codes_to_ccs(icd9_codes, crossmap):\n \"\"\"Map a list of ICD-9 codes to CCS categories.\"\"\"\n ccs_codes = []\n for code in icd9_codes:\n mapped = crossmap.map(code)\n ccs_codes.extend(mapped)\n return list(set(ccs_codes)) # deduplicate\n\n# Example patient from MIMIC-III\npatient_icd9_codes = [\"250.00\", \"401.9\", \"428.0\", \"585.3\"]\n# = Type 2 DM, Essential hypertension, Heart failure, CKD stage 3\n\npatient_ccs_codes = translate_codes_to_ccs(patient_icd9_codes, cm_9toCCS)\nprint(\"ICD-9 codes:\", patient_icd9_codes)\nprint(\"CCS codes: \", patient_ccs_codes)\nprint(f\"Vocabulary reduction: {len(icd9cm.graph.nodes)} ICD-9 codes \u2192 ~300 CCS categories\")"
"source": "# Pattern 2: Translate a patient's ICD-9 code list to CCS before modeling\n# This dramatically reduces vocabulary size.\n\ndef translate_codes_to_ccs(icd9_codes, crossmap):\n \"\"\"Map a list of ICD-9 codes to CCS categories.\"\"\"\n ccs_codes = []\n for code in icd9_codes:\n mapped = crossmap.map(code)\n ccs_codes.extend(mapped)\n return sorted(set(ccs_codes)) # deduplicate (sorted: set order is not stable)\n\n# Example patient from MIMIC-III\npatient_icd9_codes = [\"250.00\", \"401.9\", \"428.0\", \"585.3\"]\n# = Type 2 DM, Essential hypertension, Heart failure, CKD stage 3\n\npatient_ccs_codes = translate_codes_to_ccs(patient_icd9_codes, cm_9toCCS)\nprint(\"ICD-9 codes:\", patient_icd9_codes)\nprint(\"CCS codes: \", patient_ccs_codes)\nprint(f\"Vocabulary reduction: {len(icd9cm.graph.nodes)} ICD-9 codes \u2192 ~300 CCS categories\")"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[low] Unrelated behaviour change: sorted() added to translate_codes_to_ccs

The PR description says the medcode notebook is only synced to Colab. This hunk also changes the helper's return value from list(set(...)) to sorted(set(...)). The change is harmless and makes output stable, but it is an undocumented change to the example's code. Either mention it in the PR description or drop it.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI Review

suggestion: human review
decision: not available

Thank you for re-landing this work. Syncing the three tutorial notebooks with Colab and adding working source links across docs/tutorials.rst will make the tutorials much easier to use. CI coverage data wasn't available for this run, so the coverage bar couldn't be checked automatically. A maintainer will take a look and confirm. They will also check that the blob/master links match the repository's default branch name. Nothing here needs action from you right now.

Reviewed commit 7935b8e

This branch has not been deployed

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

Labels

status: manual Pending maintainer's review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants