jupytext icon indicating copy to clipboard operation
jupytext copied to clipboard

Saved ExecuteTime metadata not displayed in jupytext notebooks

Open ctcjab opened this issue 4 months ago • 6 comments

Even with configuration that correctly results in a jupytext notebook having the cell execution metadata saved inside it, the execution metadata is not shown when the jupytext notebook is opened in JupyterLab (even though it is shown as expected for the paired .ipynb):

Image
Expand for copy/pasted terminal session
❯ cat jupytext.toml 
# Ref: https://jupytext.readthedocs.io/en/latest/config.html

cell_metadata_filter = "ExecuteTime,execution,-hide_output"
notebook_metadata_filter = "-jupytext.text_representation.jupytext_version"

❯ cat foo.py
# ---
# jupyter:
#   jupytext:
#     cell_metadata_filter: ExecuteTime,execution,-hide_output
#     formats: ipynb,py:percent
#     notebook_metadata_filter: -jupytext.text_representation.jupytext_version
#     text_representation:
#       extension: .py
#       format_name: percent
#       format_version: '1.3'
#   kernelspec:
#     display_name: base
#     language: python
#     name: python3
# ---

# %% deletable=true editable=true execution={"iopub.status.busy": "2025-08-07T18:50:39.242134Z", "iopub.execute_input": "2025-08-07T18:50:39.242391Z", "iopub.status.idle": "2025-08-07T18:50:39.444469Z", "shell.execute_reply.started": "2025-08-07T18:50:39.242373Z", "shell.execute_reply": "2025-08-07T18:50:39.444109Z"} frozen=false slideshow={"slide_type": ""}
import time; time.sleep(.2)

ctcjab avatar Aug 07 '25 19:08 ctcjab

Meant to say, the https://jupytext.readthedocs.io/en/latest/advanced-options.html#metadata-filtering docs mention ExecuteTime, but the key that this metadata is getting stored under for me is execution (as you can see in the screenshot above).

Also, please let me know if https://github.com/deshaw/jupyterlab-execute-time is at least partially responsible. I can file an issue there if necessary.

Thanks!

ctcjab avatar Aug 07 '25 19:08 ctcjab

Hi @ctcjab , thank you for the report! Yes that's correct, by default we filter out both execution (likely from the extension for Jupyter Lab as you said) and ExecuteTime (likely dates back to the Jupyter notebook extension). I should update the docs to focus on the more current execution one.

Could you have a look at the notebook metadata for both the .ipynb and the .py document, in the Jupyter editor, and see if you can spot any difference? If not then maybe indeed it could be that the jupyterlab-execute-time extension assumes that all notebooks have an .ipynb extension?

mwouts avatar Aug 07 '25 21:08 mwouts

I can't spot any difference between the execution metadata in the .ipynb vs. the .py notebook: Image

I opened https://github.com/deshaw/jupyterlab-execute-time/issues/133 since it sounds like the issue is there. Could you please chime in with any additional input you have?

Thanks for the quick response!

ctcjab avatar Aug 07 '25 22:08 ctcjab

Hi @ctcjab , I took a moment to try this, and I found the following:

  • If I open the .py notebook using a right click / Notebook then I do get the previous timings.
  • However, if I open the .py notebook using a right click and Jupytext Notebook I don't get the timings.

This is the notebook that I used:

# ---
# jupyter:
#   jupytext:
#     cell_metadata_filter: execution
#     formats: py:percent
#     text_representation:
#       extension: .py
#       format_name: percent
#       format_version: '1.3'
#       jupytext_version: 1.17.3-dev
#   kernelspec:
#     display_name: itables
#     language: python
#     name: itables
# ---

# %% execution={"iopub.status.busy": "2025-08-08T18:59:58.907220Z", "iopub.execute_input": "2025-08-08T18:59:58.907574Z", "iopub.status.idle": "2025-08-08T18:59:58.913122Z", "shell.execute_reply.started": "2025-08-08T18:59:58.907545Z", "shell.execute_reply": "2025-08-08T18:59:58.912126Z"}
import time

# %% execution={"iopub.status.busy": "2025-08-08T18:59:58.914860Z", "iopub.execute_input": "2025-08-08T18:59:58.915346Z", "iopub.status.idle": "2025-08-08T18:59:58.918846Z", "shell.execute_reply.started": "2025-08-08T18:59:58.915317Z", "shell.execute_reply": "2025-08-08T18:59:58.917981Z"}
time.sleep(0)

Do you see the same?

mwouts avatar Aug 08 '25 19:08 mwouts

Oh what unexpected behavior, yes I do see the same! Thank you for testing this! So is this in fact a bug in Jupytext and I should close https://github.com/deshaw/jupyterlab-execute-time/issues/133 then?

Meanwhile I will tell the Jupytext users I'm supporting that this does work as long as they don't choose the wrong "Open With" option.

ctcjab avatar Aug 08 '25 22:08 ctcjab

While this bug is still unfixed, I would like to propose a workaround for anyone else who runs a JupyterHub instance for a large number of Jupytext users who also want double-clicking a .py file to open it as a notebook by default, such that the execution metadata is still displayed:

diff --git a/ctc-default-singleuser/overrides.json b/ctc-default-singleuser/overrides.json
index 318d679..8c7bf29 100644
--- a/ctc-default-singleuser/overrides.json
+++ b/ctc-default-singleuser/overrides.json
@@ -45,21 +45,21 @@
   "@jupyterlab/docmanager-extension:plugin": {
     "defaultViewers": {
       "markdown": "Markdown Preview",
-      "python": "Jupytext notebook"
+      "python": "Notebook"
     }
   },

Unless there are any disadvantages of doing this?

ctcjab avatar Nov 13 '25 17:11 ctcjab