Skip to content

Commit

Permalink
Preserve values "None" in the notebook metadata (#802)
Browse files Browse the repository at this point in the history
  • Loading branch information
mwouts authored Jun 10, 2021
1 parent 1cfcbd2 commit d28c175
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 4 additions & 2 deletions jupytext/header.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def recursive_update(target, update):
for key in update:
value = update[key]
if value is None:
target.pop(key, None)
del target[key]
elif isinstance(value, dict):
target[key] = recursive_update(target.get(key, {}), value)
else:
Expand Down Expand Up @@ -225,7 +225,9 @@ def header_to_metadata_and_cell(

if ended:
if jupyter:
recursive_update(metadata, yaml.safe_load("\n".join(jupyter))["jupyter"])
extra_metadata = metadata
metadata = yaml.safe_load("\n".join(jupyter))["jupyter"]
recursive_update(metadata, extra_metadata)

lines_to_next_cell = 1
if len(lines) > i + 1:
Expand Down
2 changes: 2 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -1376,3 +1376,5 @@ def test_round_trip_with_null_metadata_792(tmpdir, cwd_tmpdir, python_notebook):
write(nb, "test.ipynb")
jupytext(["--to", "py:percent", "test.ipynb"])
jupytext(["--to", "ipynb", "test.py"])
nb = read("test.ipynb")
assert nb.metadata.kernelspec.env is None

0 comments on commit d28c175

Please sign in to comment.