Skip to content

Fix invalid JSON in DiCE_getting_started_feasible notebook (#439)#468

Open
jbbqqf wants to merge 1 commit into
interpretml:mainfrom
jbbqqf:fix/439-notebook-json
Open

Fix invalid JSON in DiCE_getting_started_feasible notebook (#439)#468
jbbqqf wants to merge 1 commit into
interpretml:mainfrom
jbbqqf:fix/439-notebook-json

Conversation

@jbbqqf
Copy link
Copy Markdown

@jbbqqf jbbqqf commented May 9, 2026

Summary

docs/source/notebooks/DiCE_getting_started_feasible.ipynb shipped with a
trailing comma after \"nbformat_minor\": 4 (last lines of the file), which
made the file invalid JSON. As @rmnldwg reported in #439, this prevents the
notebook from rendering on GitHub and from opening in JupyterLab
(NotJSONError). #425 reports the same symptom.

The notebook is currently pytest.mark.skip-ed in tests/test_notebooks.py
("needs changes after latest refactor"), so the malformed JSON has been able
to sit in the repo for >2 years without CI catching it.

Why

Two changes here, the second is the load-bearing one:

  1. Fix: drop the trailing comma so the notebook parses as JSON again.
  2. Regression guard: add a tiny test_notebook_is_valid_json test that
    json.loads every .ipynb under docs/source/notebooks/. Cheap, no
    nbconvert/jupyter execution required, runs in the default test job. This
    means a notebook with malformed JSON can no longer be merged silently
    even if its nbconvert test stays skipped.

Reproduce BEFORE/AFTER yourself (copy-paste)

# Run from a fresh clone of interpretml/DiCE
set -e
cd /tmp && rm -rf DiCE-repro && git clone https://github.com/interpretml/DiCE.git DiCE-repro
cd DiCE-repro

# --- BEFORE: origin/main ---
git checkout origin/main -- docs/source/notebooks/DiCE_getting_started_feasible.ipynb
python -c "import json; json.load(open('docs/source/notebooks/DiCE_getting_started_feasible.ipynb'))" || echo "BEFORE: JSONDecodeError (expected)"
# Expected: \"Illegal trailing comma before end of object: line 364 column 21\"

# --- AFTER: this PR's branch ---
git fetch https://github.com/jbbqqf/DiCE.git fix/439-notebook-json
git checkout FETCH_HEAD -- docs/source/notebooks/DiCE_getting_started_feasible.ipynb tests/test_notebooks.py
python -c "import json; json.load(open('docs/source/notebooks/DiCE_getting_started_feasible.ipynb')); print('AFTER: parses OK')"
# Expected: \"AFTER: parses OK\"

pip install -q -e . pytest nbformat
pytest tests/test_notebooks.py::test_notebook_is_valid_json -q
# Expected: 8 passed (one per notebook under docs/source/notebooks/)

What I ran locally

  • pytest tests/test_notebooks.py::test_notebook_is_valid_json8 passed
  • Confirmed json.load raises on origin/main and parses on this branch
  • Notebook still renders identically — only the trailing comma is removed

Edge cases

case behaviour
All other notebooks under docs/source/notebooks/ All parse; new test now guards them
Future PR that introduces a malformed notebook Test fails in default CI even if nbconvert run is skipped
Notebooks excluded via advanced_notebooks skip list Still validated by JSON test (no execution required)

AI disclosure

This change was prepared with the assistance of Claude (Anthropic).
The author reviewed every line and is responsible for the final result.

Removes the trailing comma after `"nbformat_minor": 4`, which made the
notebook fail to parse as JSON: GitHub's preview refused to render it
and JupyterLab raised `NotJSONError` when opening it.

Adds a `test_notebook_is_valid_json` parametrized test that loads every
shipped notebook with `json.load`, so a malformed notebook can no longer
slip into the repo unnoticed (the existing nbconvert test for this
notebook is `pytest.mark.skip`-ed).

Closes interpretml#439, interpretml#425.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant