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

Remove deepcopy #694

Merged
merged 6 commits into from Oct 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 1 addition & 3 deletions papermill/engines.py
@@ -1,6 +1,5 @@
"""Engines to perform different roles"""
import sys
import copy
import datetime
import dateutil

Expand Down Expand Up @@ -99,8 +98,7 @@ class NotebookExecutionManager(object):
def __init__(
self, nb, output_path=None, log_output=False, progress_bar=True, autosave_cell_every=30
):
# Deep copy the input to isolate the object being executed against
self.nb = copy.deepcopy(nb)
self.nb = nb
self.output_path = output_path
self.log_output = log_output
self.start_time = None
Expand Down
20 changes: 9 additions & 11 deletions papermill/tests/test_engines.py
Expand Up @@ -36,14 +36,6 @@ def setUp(self):
self.foo_nb = copy.deepcopy(self.nb)
self.foo_nb.metadata['foo'] = 'bar'

def test_nb_isolation(self):
"""
Tests that the engine notebook is isolated from source notebook
"""
nb_man = NotebookExecutionManager(self.nb)
nb_man.nb.metadata['foo'] = 'bar'
self.assertNotEqual(nb_man.nb, self.nb)

def test_basic_pbar(self):
nb_man = NotebookExecutionManager(self.nb)

Expand Down Expand Up @@ -343,7 +335,11 @@ def execute_managed_notebook(cls, nb_man, kernel_name, **kwargs):
nb_man.cell_complete(cell)

with patch.object(NotebookExecutionManager, 'save') as save_mock:
nb = CellCallbackEngine.execute_notebook(self.nb, 'python', output_path='foo.ipynb')
nb = CellCallbackEngine.execute_notebook(
copy.deepcopy(self.nb),
'python',
output_path='foo.ipynb'
)

self.assertEqual(nb, AnyMock(NotebookNode))
self.assertNotEqual(self.nb, nb)
Expand Down Expand Up @@ -373,7 +369,9 @@ def execute_managed_notebook(cls, nb_man, kernel_name, **kwargs):
with patch.object(NotebookExecutionManager, 'save') as save_mock:
with patch.object(NotebookExecutionManager, 'complete_pbar') as pbar_comp_mock:
nb = NoCellCallbackEngine.execute_notebook(
self.nb, 'python', output_path='foo.ipynb'
copy.deepcopy(self.nb),
'python',
output_path='foo.ipynb'
)

self.assertEqual(nb, AnyMock(NotebookNode))
Expand Down Expand Up @@ -407,7 +405,7 @@ def test_nb_convert_engine(self):
with patch.object(engines, 'PapermillNotebookClient') as client_mock:
with patch.object(NotebookExecutionManager, 'save') as save_mock:
nb = NBClientEngine.execute_notebook(
self.nb,
copy.deepcopy(self.nb),
'python',
output_path='foo.ipynb',
progress_bar=False,
Expand Down