Live data from Hacker News

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

news.ycombinator.com

11–20 of 30 posts

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

#12
In addition to this, you can keep a dual markdown version that uses a much more human-readable syntax and preserves both code and markdown sections of the Jupyter notebook. This is also via jupytext. In both jupyterlab and jupyter you can pair the two versions (something like what is discussed here: https://www.wrighters.io/jupytext-notebooks-as-markdown-or-p...) and they will stay in sync automatically.

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

#14
I used something as a precommit hook in the past that removed plots and other rendered content and only kept text and code in git index. I'm almost sure it was https://github.com/kynan/nbstripout but it's been a while and I could be wrong.

Once the hook was in place git diff worked well enough to not need any other diffing tool.

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

#15
post #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…

edit: Googling reveals nbdime, has this been looked into? - https://nbdime.readthedocs.io/en/latest/

Not OP but I can imagine easily the need for what he's asking.

You'll find a lot of algorithms for data and image processing saved as notebooks these days offered to you. Let's say you make some changes from the provided code and after a handful of changes something is not working right. You might want to diff from where you are back to a working version in hopes that differences that emerge might clue you into where to look for where the problem might be.

As an aside, I want to say Jupyter notebooks (moreso jupyterlab) is sort of a disruptive change to our coding workflows. We've had interpreters for a long time sure, but creating interactive graphs on-the-fly is a godsend, insights come to you in such a workflow that wouldn't otherwise. I hope this catches on, I actually want my shell terminal to become more Jupyter-like. Also, fun fact: did you know you could do real-time collaboration on Juypter notebooks? https://jupyterlab.readthedocs.io/en/stable/user/rtc.html

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

#16
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.

On the one hand: cool, if you're an avid emacsen or a vimmer, yeah, ok. OTOH, gosh that is such a cluttered and cumbersome setup. Just bring in vim/emacs bindings to your jupyter: https://github.com/lambdalisue/jupyter-vim-binding. There's a handful of plugins, choose one.

Whatever the final solution everyone decides should be, I just hope it doesn't involve having two redundant windows open side-by-side like that. Ideally, it should probably be instantiating an emacs client within Jupyter as that seems the most logical.

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

#17
post #14

I used something as a precommit hook in the past that removed plots and other rendered content and only kept text and code in git index. I'm almost sure it was https://github.com/kynan/nbstripout but it's been a while and I could be wrong. Once the hook was in place git diff worked well enough to not need any other diffing tool.

yep, can confirm, it basically filters out any notebook output from version control (while keeping it intact in the notebook file itself). This works seamlessly with diffing, committing, staging, etc.

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

#19
post #15
post #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…

edit: Googling reveals nbdime, has this been looked into? - https://nbdime.readthedocs.io/en/latest/ Not OP but I can imagine easily the need for what he's asking. You'll find a lot of algorithms for data and image processing saved as notebooks these days offered to you. Let's say you make some changes from the provided code and after a handful of changes something is not working right. You might want to diff from wh…

Oh I can totally imagine use-cases too, but I’d love to hear what the OP’s use case actually is. I also agree completely on the disruption that Jupyter brings, and that it has just massive benefits. But when a workflow isn’t giving you everything you want, it’s worth evaluating whether the tools you’re using are the right tools for the job, right?

One example would be that Jupyter is well designed for a lot of prototyping and for single-person scenarios. It’s well designed for sharing and for including notes and narrative with code. It’s just not really designed for multi-user workflows. That’s not a negative in my book, it’s just a fact that makes me reach for a different tool when I need to collaborate.

Also don’t overlook Spyder, which is part of the same ecosystem as Jupyter, they’re usually bundled together, and Spyder gives you the interactive features you want but might better support a production workflow that is multi-user, collaborative, and also more easily diffable.

All that said, it might be awesome if someone builds a Jupyter diff tool that is designed to ignore the output cells!

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

#20
post #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…

Not OP but restart and clear output can be quite compute intensive if you're working with big datasets or training ML models. There are many ways to mitigate this like saving weights and only redo the inference but it's not always worth it when you're iterating through models and parameters or doing exploratory data analysis. Most of the time you want to just keep results/outputs of previous run and improve from there
Post reply on HN