nteract / papermill

📚 Parameterize, execute, and analyze notebooks
http://papermill.readthedocs.io/en/latest/
BSD 3-Clause "New" or "Revised" License
5.91k stars 425 forks source link

Cell that starts with %%time does not report errors #781

Closed vincent-163 closed 4 months ago

vincent-163 commented 7 months ago

🐛 Bug

Running a new notebook with two cells via papermill: (assuming results.json does not exist)

%%time
# cell 1
with open('results.json') as f:
    results = json.load(f)
print(results)

Gives

NameError: name 'results' is not defined`

for the second cell. The first cell's error is silently ignored without any warnings, and the only clue is that the cell's time is not reported as well.

If %%time is removed from the first cell, the error is reported properly and the execution is interrupted at the first cell:

FileNotFoundError: [Errno 2] No such file or directory: 'results.json'
zmbc commented 4 months ago

This is actually an upstream issue in IPython: https://github.com/ipython/ipython/issues/12971

MSeal commented 4 months ago

I put a comment on that thread, it is indeed a magic implementation issue and not a notebook or papermill specific control point.