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

Removing execution_count key completely from "output_type": "execute_result" produces Invalid Notebook in github #19

Open
grzegorz700 opened this issue Oct 21, 2024 · 0 comments

Comments

@grzegorz700
Copy link

In the case of removing execution_count (+metadata) while preserving outputs produce situation with removing execution_count key field entirely instead of putting the null value. After pushing it to GitHub it produces error:

Invalid Notebook
'execution_count' is a required property
Using nbformat v5.10.4 and nbconvert v7.16.1

So, the little change in the code should fix it.

Example:

  {
   "cell_type": "code",
-  "execution_count": 100,
+  "execution_count": null,
   "id": "4eea4a7f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2471\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "[('TEXT1',\n",
       "  Counter({'middle': 1})),\n",
       " ('TEXT2',\n",
       "  Counter({'middle': 1})),\n",
       " ('TEXT3.',\n",
       "  Counter({'middle': 1}))]"
      ]
     },
-    "execution_count": 100,
-    "metadata": {},
-    "output_type": "execute_result"
+    "output_type": "execute_result",
+    "metadata": {}
    }
   ],
   "source": [
    "# Display XYZ\n",
    "print(len(result))\n",
    "result[:3]"
   ]
  },

It's data displayed when we don't print them, but it's the last reference in the cell.

The probable fix is change from :

obj.remove("execution_count");

to:

obj["execution_count"] = json!(null);

I will post it as a pull request when I have some time. But feel free to do it instead of me, and test it on your own. And quickly release a new fixed version :)

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

No branches or pull requests

1 participant