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

Add support for parameters and/or tags assignment (papermill) #1121

Closed
MSeal opened this issue Nov 4, 2019 · 23 comments
Closed

Add support for parameters and/or tags assignment (papermill) #1121

MSeal opened this issue Nov 4, 2019 · 23 comments
Assignees
Labels
feature-request Request for new features or functionality on-testplan

Comments

@MSeal
Copy link

MSeal commented Nov 4, 2019

Feature: Notebook Editor, Interactive Window, Python Editor cells

Add ability to set metadata tags on a cell, like notebook classic supports in the gif below (but maybe with a better interface for it).

enable_parameters

Description

Cell tags are used as a convention based pattern for converting notebooks in a few contexts. The papermill library uses the parameters and injected-parameters tags to manage user inputs to notebook executions. NBConvert has notebook manipulation processors that filter or convert cells based on tags. Overall while it was originally used for metadata matching purposes, it's use for production execution paths has become a necessity with Jupyter today. Have a minimal way to manage the cell tags would go a long way for cross-tooling support.

@DavidKutu
Copy link

Thanks for letting us know!
We'll look into it.

@S-UP
Copy link

S-UP commented Feb 20, 2020

I want to second this. I am very happy with VSCode as my primary Python editor but when looking for a way to parameterize my notebook via papermill I ran into the above issue of not being able to set parameters.

@arliber
Copy link

arliber commented Apr 30, 2020

Any possible work around the missing tag options in VS Code?

@blessymoses
Copy link

+1
Any workarounds available?

@va1ha11a
Copy link

+1
I work around this by opening the NB as JSON (separately, to the notebook editor) and manually add the tag in the JSON

@greazer greazer changed the title Add support for tags assignment (papermill) DS: Add support for tags assignment (papermill) Jul 30, 2020
@greazer greazer changed the title DS: Add support for tags assignment (papermill) DS: Add support for tags assignment (papermill) (Add support for cell metadata) Jul 30, 2020
@IanMatthewHuff IanMatthewHuff transferred this issue from microsoft/vscode-python Nov 13, 2020
@greazer greazer changed the title DS: Add support for tags assignment (papermill) (Add support for cell metadata) Add support for parameters and/or tags assignment (papermill) (Add support for cell metadata) Nov 14, 2020
@aeturrell
Copy link

+1. This would be really helpful when using with JupyterBook.

@kennysong
Copy link

+1. Is this being planned for VSCode Jupyter or the new native notebook integration?

@DavidKutu
Copy link

Once we are ready to roll out the new notebook for everyone, we'll come back to adding more features like this one.

@tsuga
Copy link

tsuga commented May 28, 2021

FYI, a workaround is mentioned in #1182 (comment)

@saldroubi
Copy link

saldroubi commented Oct 7, 2021

Please add this feature soon. The workaround, jupyter power tools extension, does not work with latest vs code insider.
An issue was logged DonJayamanne/vscode-jupyterpowertools#3 but it seems that the developer has not been active for about 5 months.

@acgzr
Copy link

acgzr commented Oct 16, 2021

+1 I work around this by opening the NB as JSON (separately, to the notebook editor) and manually add the tag in the JSON

As mentioned, it is possible to do so manually for now. I do it by right-clicking the .ipynb file in the Explorer window, selecting "Open With..." and choosing "Text Editor". Then you can just find the cell you want to add tags to and put something like "tags": ["abc123"] inside the "metadata" curly brackets.

This is the only way I've been able to use the TagRemovePreprocessor capabilities from nbconvert while attempting to hide certain code input cells when converting to HTML.

@jucor
Copy link

jucor commented Oct 18, 2021

This would be very needed when using unit tests with https://github.com/nteract/testbook/. Thanks for considering!

@jonyzambrano01
Copy link

+1!

@mhorlacher
Copy link

Is this implemented yet? Would be very useful for papermill!

@shaahrzad91
Copy link

shaahrzad91 commented May 19, 2022

Does anybody know how to add parameter "add tag" in VS code?

@torext
Copy link

torext commented Jun 15, 2022

This seems like pure user interface work, so hoping this won't be pushed out for much longer.

@ADN8B
Copy link

ADN8B commented Jul 9, 2022

+1
It would be great if you could add cell tags in Vscode.

@tarunn90
Copy link

+1!

@PaleNeutron
Copy link

I need tags!

@JamesIgoe
Copy link

would be helpful, yes...

@rezan21
Copy link

rezan21 commented Aug 19, 2022

Meanwhile, I've created a script which can automate adding certain tags, e.g. 'parameters' for papermill, to a notebook. It requires an indicator comment. (by default, it looks for the first occurrence of "default param".) You'd need to add the indicator as a comment to the cell you wish to add the tag to.

import json


def add_tag_to_nb(nb_path: str, tag: str = "parameters", indicator: str = "default param"):
    # read notebook
    with open(nb_path) as file:
        nb = json.load(file)

    for i, cell in enumerate(nb["cells"]):
        cell_text = "".join(cell["source"])
        # find first cell with the indicator
        if indicator in cell_text:
            cell["metadata"]["tags"] = cell["metadata"].get("tags", [])  # existing tags
            if tag not in cell["metadata"]["tags"]:
                cell["metadata"]["tags"].append(tag)  # add tag
            break
    else:
        print(f"{indicator} not found in {nb_path}!")
        return None

    nb["cells"][i] = cell
    # save
    with open(nb_path, "w") as file:
        json.dump(nb, file)

@rebornix
Copy link
Member

Hi all, thank you for the suggestion and all your feedbacks! We published a new extension Jupyter Cell Tags https://marketplace.visualstudio.com/items?itemName=ms-toolsai.vscode-jupyter-cell-tags to the marketplace which you can play around with today. The extension will be available through Jupyter extension pack later.

With this extension, you should be able to mark a cell as papermill parameters, or insert a new random tag from the cell toolbar

image

Once a tag is added to a cell, it will be rendered in the cell status bar so you can delete them with ease

image

You can add new cell tags through status bar item + Tag as well

image


Give it a try and feel free to share your thoughts on how it works and what else we can do to improve the tag editing experience.

@rebornix rebornix changed the title Add support for parameters and/or tags assignment (papermill) (Add support for cell metadata) Add support for parameters and/or tags assignment (papermill) Sep 21, 2022
@rebornix rebornix added this to the September 2022 milestone Sep 21, 2022
@mertgoksel
Copy link

mertgoksel commented Oct 12, 2022

Cannot edit cell tags in R kernel. The JSON editor doesnt open.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 26, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature-request Request for new features or functionality on-testplan
Projects
None yet
Development

No branches or pull requests