Hi,
I want to use TagRemovePreprocessor.remove_cell_tag when converting a notebook to a script, but this preprocessor seems to work only with html output ? Is it a bug or normal behavior ?
I have recreated this behavior. I too am curious if this is a bug or normal behavior?
The following config file does produce a script named script.py but, includes the cells tagged with nbonly.
c.NbConvertApp.output_base = "script"
c.NbConvertApp.export_format = "script"
c.TagRemovePreprocessor.remove_cell_tags.add("nbonly")
The following config file produces a file named script.html and correctly excluded the cells tagged with nbonly
c.NbConvertApp.output_base = "script"
c.NbConvertApp.export_format = "html"
c.TagRemovePreprocessor.remove_cell_tags.add("nbonly")
In the meantime I'll clone the repo and see if I can add anything. If anyone is willing to accelerate my research, I'm always open to suggestions on where in the codebase to start : )
Same problem here for PDF outputs. This preprocessor seems to do nothing for non-HTML targets.
@yaumeg
If you need a Python script, --to python will work and --to script will not.
(workspace) bash-3.2$ jupyter nbconvert data_filter.ipynb --to script --TagRemovePreprocessor.remove_cell_tags={\"remove_cell\"}
[NbConvertApp] Converting notebook data_filter.ipynb to script
[NbConvertApp] Writing 6784 bytes to data_filter.py
(workspace) bash-3.2$ jupyter nbconvert data_filter.ipynb --to python --TagRemovePreprocessor.remove_cell_tags={\"remove_cell\"}
[NbConvertApp] Converting notebook data_filter.ipynb to python
[NbConvertApp] Writing 5121 bytes to data_filter.py
I am also wondering if this is a bug or an intended design. Nevertheless, the nbconvert doc should be improved.
It looks like that for some exporters you need to explicitly enable it with --TagRemovePreprocessor.enabled=True so for example
jupyter nbconvert nbconvert --log-level='DEBUG' --to notebook --TagRemovePreprocessor.remove_cell_tags='{"note"}' L01.ipynb --TagRemovePreprocessor.enabled=True
logs
[NbConvertApp] Converting notebook L01.ipynb to notebook
[NbConvertApp] Notebook name is 'L01'
[NbConvertApp] Applying preprocessor: TagRemovePreprocessor
[NbConvertApp] Applying preprocessor: coalesce_streams
[NbConvertApp] Writing 1335 bytes to L01.nbconvert.ipynb
and actually fliters out the cells.
Thanks @mapio! I experienced the same issue and your solution of explicitly enabling the tag remove processor worked for me.
Most helpful comment
I have recreated this behavior. I too am curious if this is a bug or normal behavior?
The following config file does produce a script named script.py but, includes the cells tagged with nbonly.
c.NbConvertApp.output_base = "script" c.NbConvertApp.export_format = "script" c.TagRemovePreprocessor.remove_cell_tags.add("nbonly")The following config file produces a file named script.html and correctly excluded the cells tagged with nbonly
c.NbConvertApp.output_base = "script" c.NbConvertApp.export_format = "html" c.TagRemovePreprocessor.remove_cell_tags.add("nbonly")In the meantime I'll clone the repo and see if I can add anything. If anyone is willing to accelerate my research, I'm always open to suggestions on where in the codebase to start : )