microsoft / vscode-jupyter

VS Code Jupyter extension
https://marketplace.visualstudio.com/items?itemName=ms-toolsai.jupyter
MIT License
1.3k stars 293 forks source link

"Clear All Output" is greyed out and doesn't clear execution count unless output is available #15266

Open MarcBarlett opened 8 months ago

MarcBarlett commented 8 months ago

Applies To

What happened?

Create a new cell in an *.ipynb. run an import statement, the execution count increments. expected that this execution statement could be cleared with the "Clear All Outputs" button it cannot. image

add a print statement to the cell and run. The "Clear All Outputs" is now available and can be used to clear the execution count as well as outputs. image

"Clear All Outputs" should be available to clear execution counts even if none of the cells have printed outputs.

VS Code Version

1.86.2

Jupyter Extension Version

2024.1.1

Jupyter logs

No response

Coding Language and Runtime Version

Python v 3.10.10

Language Extension Version (if applicable)

No response

Anaconda Version (if applicable)

No response

Running Jupyter locally or remotely?

None

ScottBoyce commented 6 months ago

Same effect for me with

VS Code Version 1.89.1

Jupyter Extension Version 2024.4.0

Coding Language and Runtime Version Python v 3.12.2

drush0 commented 2 months ago

Seeing the same on

VS Code V1.93.0 Jupyter Extension V2024.8.1 Python 3.12.1

This seems to be a regression from this issue right?

ejfdickinson commented 1 month ago

There is a new issue here from v1.93.1, with both Jupyter v2024.8 and v2024.7. See further testing below.

From v1.93.1, Clear All Outputs, even if available, does not affect execution count of cells with no output. Execution count is displayed as null (flushed in the GUI) but does not actually reset in the notebook source. So this is a further regression and #16052 is not a duplicate of this issue, it's a different problem. @amunger @SmallhillCZ

Note that this issue (#15266) does still apply - if no cells have output, Clear All Outputs is greyed. However, if any cell has output, Clear All Outputs is available and at < 1.93.1 would clear execution count from all cells, even those with no output.

Comparison (expected behaviour before 1.93.1 as described by OP):

VS Code 1.92.2 Jupyter Extension 2024.7 Python 3.9.13

  1. Run a cell with no output - can't clear anything.

image

  1. Run a cell with output - can clear everything.

image

  1. After Clear All Outputs, execution count goes back to null on both cells.

image

New behaviour as follows:

VS Code 1.93.1 Jupyter Extension 2024.7 Python 3.9.13

Apparent behaviour in the GUI is the same (execution count appears to be null), but the first cell does not have its execution count cleared in the source:

 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "print(1)"
   ]
  }
 ],

Update to Jupyter v2024.8.1 gives the same behaviour with v1.93.1.

bernard-123lb commented 1 month ago

Source Control

Just in case this was not immediately obvious to someone, "execution_count": 1 is problematic for source control. We want to nullify/clear all outputs before committing to reduce merge conflicts. So I have to manually nullify those before committing directly in the json file. I noticed that commits from users of the original Jupyter IDE seems to always have nullified execution_count as expected.

chrispy-snps commented 4 weeks ago

We are also running into this in v1.94.2. And as @bernard-123lb says, the merge conflict aspect is particularly problematic.

DonJayamanne commented 3 weeks ago

@ejfdickinson @drush0 I've re-opened the issue https://github.com/microsoft/vscode-jupyter/issues/16052 & will be fixing that.

DonJayamanne commented 3 weeks ago

TEMPORARY SOLUTION/WORK AROUND

Please use the command Notebook: Clear Cell Outputs I understand this doesn't fix the problem with the icon not being enabled, hence temporar work around