Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TagRemovePreprocessor.remove_cell_tags works only with html output #764

Open
yaumeg opened this issue Feb 14, 2018 · 7 comments
Open

TagRemovePreprocessor.remove_cell_tags works only with html output #764

yaumeg opened this issue Feb 14, 2018 · 7 comments

Comments

@yaumeg
Copy link

yaumeg commented Feb 14, 2018

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 ?

@ariedl
Copy link

ariedl commented Mar 22, 2018

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 : )

@ProfFan
Copy link

ProfFan commented Apr 27, 2018

Same problem here for PDF outputs. This preprocessor seems to do nothing for non-HTML targets.

@haokanga
Copy link

haokanga commented May 27, 2018

@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.

@mapio
Copy link

mapio commented Feb 6, 2019

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.

@joelostblom
Copy link
Contributor

Thanks @mapio! I experienced the same issue and your solution of explicitly enabling the tag remove processor worked for me.

@amine-aboufirass
Copy link

@mapio I ran this command on a notebook containing %%svg magic:

jupyter nbconvert --to notebook chapter_1.ipynb --TagRemovePreprocessor.enabled=True --TagRemovePreprocessor.remove_input_tags=remove_cell

The resulting notebook had a validation error:

Notebook validation failed: Additional properties are not allowed ('transient' was unexpected):
{
 "cell_type": "code",
 "execution_count": 7,
 "id": "specific-report",
 "metadata": {
  "tags": [
   "remove_cell"
  ],
  "trusted": false
 },
 "outputs": [
  {
   "data": {
    "image/svg+xml": "<svg width=\"100\" height=\"100\">\n  <circle cx=\"50\" cy=\"50\" r=\"40\" stroke=\"green\" stroke-width=\"4\" fill=\"yellow\"/>\n</svg>",
    "text/plain": "<IPython.core.display.SVG object>"
   },
   "metadata": {},
   "output_type": "display_data"
  }
 ],
 "source": "%%svg\n<svg width=\"100\" height=\"100\">\n  <circle cx=\"50\" cy=\"50\" r=\"40\" stroke=\"green\" stroke-width=\"4\" fill=\"yellow\" />\n</svg>",
 "transient": {
  "remove_source": true
 }
}

@mapio
Copy link

mapio commented Mar 17, 2021

@mapio I ran this command on a notebook containing %%svg magic:

I've never used svg in a notebook, sorry…

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants