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

Allow for nested Jupyter code cells #5045

Closed
PALuczak opened this issue Mar 5, 2021 · 6 comments
Closed

Allow for nested Jupyter code cells #5045

PALuczak opened this issue Mar 5, 2021 · 6 comments
Assignees
Labels
feature-request Request for new features or functionality interactive-window Impacts interactive window

Comments

@PALuczak
Copy link

PALuczak commented Mar 5, 2021

It would be very useful to be able to nest Jupyter code calls based on indentation. This would make it possible to run for example just a part of a loop. For example:

# %% < -- top-level cell
j = 0
for i in range(10):
    # %% < -- sub cell 1
    print(i)
    # %% < -- sub cell 2
    for k in range(10):
        # %% < -- sub sub cell 1
        print(i * i)
    # %% < -- sub cell 3
    j += i
# %%  < -- another top-level cell
print(j)

in this scenario triggering the outer cell would run the entire loop, while the inner cell would only run the code inside the loop.
This would be especially useful during data cleaning, where the processing step needs to be fine-tuned before being run on the whole dataset. If it makes the implementation more convenient, the inner cells could also be designated by adding additional percent characters for each nesting level, i.e.: # %% - top-level cell, # %%% - subcell, # %%%% - subsubcell etc.

@claudiaregio
Copy link
Contributor

Hi @PALuczak, if you select code with your mouse you can right click and select the option "Run Selection/Line in Interactive Window". You can even adjust the keyboard shortcut for this if you would like a different one.
Does that solution work for you?

@PALuczak
Copy link
Author

PALuczak commented Mar 8, 2021

That is more of a workaround than a solution. Selection is quite error-prone and oftentimes it leads to selecting either one too many or one too few lines. The proposed subcells would significantly reduce such errors.

Furthermore, this additional structure would be very useful in teaching, as we would be able to show the processing step-by-step before running it on the whole dataset without having to duplicate code or having to ensure that they select the exact line numbers that describe a particular step.

@tomekjaworski
Copy link

Hi @claudiaregio, I agree with @PALuczak. The problem with here is UI ergonomics and usability. In your approach you have to use a mouse, select a part of your code, right click, select an option. Or, with keyboard shortcuts - select a part of code (with shift and arrows) and then press the Run Selection shortcut. In contrary to this a single shortcut (e.g. Ctrl+Enter) in a subcell sounds quite effective. Moreover, such feature would be very helpful during code tuning/debugging sessions - you make a small change and execute it to see the result asap.

@andycraig
Copy link
Contributor

Another approach to this is the proposal to auto-detect code blocks around the cursor, with Shift+Enter executing the whole block: #1471 Then you could run the whole for loop when the cursor is on the for line. It wouldn't give exactly the same functionality but there is some overlap.

@PALuczak
Copy link
Author

While there is some slight overlap with #1471, the approach proposed here is significantly more flexible as it would allow for more incremental splits. Oftentimes, either the first or the last step in the loop is costly (i.e. getting/saving data) so being able to split it from the other steps would be quite useful.

Additionally, as mentioned in my previous comment, being able to specify blocks manually would be very useful in education as it would allow for creating step-by-step tutorials for students.

@greazer greazer added the interactive-window Impacts interactive window label Aug 3, 2021
@greazer greazer added feature-request Request for new features or functionality and removed enhancement labels May 4, 2022
@amunger
Copy link
Contributor

amunger commented Dec 7, 2022

thanks for the suggestion, unfortunately I don't think there is enough interest for us to prioritize this feature

@amunger amunger closed this as not planned Won't fix, can't repro, duplicate, stale Dec 7, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 16, 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 interactive-window Impacts interactive window
Projects
None yet
Development

No branches or pull requests

8 participants