Skip to content

Commit 30f3d81

Browse files
authored
Only require nbformat_minor for v4 (#342)
1 parent 2916339 commit 30f3d81

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

nbformat/v4/convert.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,14 @@ def upgrade(nb, from_version=None, from_minor=None):
4040
from_version = nb["nbformat"]
4141
if not from_minor:
4242
if "nbformat_minor" not in nb:
43-
raise validator.ValidationError(
44-
"The notebook does not include the nbformat minor which is needed"
45-
)
46-
from_minor = nb["nbformat_minor"]
43+
if from_version == 4:
44+
raise validator.ValidationError(
45+
"The v4 notebook does not include the nbformat minor, which is needed."
46+
)
47+
else:
48+
from_minor = 0
49+
else:
50+
from_minor = nb["nbformat_minor"]
4751

4852
if from_version == 3:
4953
# Validate the notebook before conversion

tests/test3_no_min_version.ipynb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"metadata": {
3+
"name": ""
4+
},
5+
"nbformat": 3,
6+
"worksheets": [
7+
{
8+
"metadata": {},
9+
"cells": []
10+
}
11+
]
12+
}

tests/test_validator.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,12 @@ def test_notebook_invalid_without_min_version():
355355
validate(nb)
356356

357357

358+
def test_notebook_v3_valid_without_min_version():
359+
with TestsBase.fopen("test3_no_min_version.ipynb", "r") as f:
360+
nb = read(f, as_version=4)
361+
validate(nb)
362+
363+
358364
def test_notebook_invalid_without_main_version():
359365
pass
360366

0 commit comments

Comments
 (0)