Live data from Hacker News

Ask HN: Are there any good Diff tools for Jupyter Notebooks?

news.ycombinator.com

1–10 of 30 posts

Ask HN: Are there any good Diff tools for Jupyter Notebooks?

#1
This is one of the biggest pain points of my work - reviewing diffs of Jupyter Notebooks.

Does anyone have any good tools for this that preserve the visuals of the Notebooks.

My approach has always been rendering the files as .py without the cell outputs and comparing which is a big PITA.

Anyone have any advice?

Re: Ask HN: Are there any good Diff tools for Jupyter Notebooks?

#6
Can you talk more about why you’re working in Jupyter Notebooks at a level that needs diff reviews? Are you reviewing your own work, or the work of others?

One option would be to start a policy to always “restart and clear output” before saving. This cleans the output cells and makes the .ipynb files diffable. Just happens to also make them nice for storing in version control.

Another option would be to work in pure python files in the first place, and only use Jupyter after the fact. The close brother to Jupyter is the Spyder IDE, which gives you most of the benefits of quick visual outputs, but also has a nice python debugger built in.

Re: Ask HN: Are there any good Diff tools for Jupyter Notebooks?

#8
You can use jupytext to maintain dual .py/.ipynb representation of notebooks and keep both versions in sync:

https://github.com/mwouts/jupytext/blob/main/docs/paired-not...

It works both ways, it can update the .py file each time you save the notebook, or you can edit the .py file and have the jupytext command line tool update the .ipynb.

Re: Ask HN: Are there any good Diff tools for Jupyter Notebooks?

#9
post #8

You can use jupytext to maintain dual .py/.ipynb representation of notebooks and keep both versions in sync: https://github.com/mwouts/jupytext/blob/main/docs/paired-not... It works both ways, it can update the .py file each time you save the notebook, or you can edit the .py file and have the jupytext command line tool update the .ipynb.

This with https://github.com/untitled-ai/jupyter_ascending + your Editor to have a supercharged notebook workflow.

Re: Ask HN: Are there any good Diff tools for Jupyter Notebooks?

#10
post #2

There is https://nbdime.readthedocs.io/en/latest/ , although I haven't used it personally to know how good it is.

I used this and can recommend it, since it also shows you the outputs of different versions.

But as another commenter said, when I got to the point of needing to diff my notebooks, I realized that I could move some of the code into separate python files.

If you're a business analyst, one use case is if you need to process some data e.g. every quarter, but the data changes a bit every time so you need to update the approach slightly (e.g. data structure changes, new mapping rules). With nbdiff it's easy to keep track of changes while having some helpful visualizations in the same file.

Post reply on HN