Skip to content

Commit 54f6c03

Browse files
surdouskiMSeal
andauthored
Remove deepcopy (#694)
* Remove deepcopy Just found this one after updating something internal and hitting serialization issue again. See previous PR regarding deepcopy (they have no purpose). * Fixed flake8 issues * Add deepcopy to test Engine input isolation removed, update test with deepcopy. * Isolation no longer expected Remove test with this expectation. * Reconfigure tests no isolation nb. Used deepcopy where necessary when tests used the isolated nb expectation in unittest logic for assertion checks. Co-authored-by: Matthew Seal <[email protected]>
1 parent fdf4880 commit 54f6c03

File tree

2 files changed

+10
-14
lines changed

2 files changed

+10
-14
lines changed

papermill/engines.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"""Engines to perform different roles"""
22
import sys
3-
import copy
43
import datetime
54
import dateutil
65

@@ -99,8 +98,7 @@ class NotebookExecutionManager(object):
9998
def __init__(
10099
self, nb, output_path=None, log_output=False, progress_bar=True, autosave_cell_every=30
101100
):
102-
# Deep copy the input to isolate the object being executed against
103-
self.nb = copy.deepcopy(nb)
101+
self.nb = nb
104102
self.output_path = output_path
105103
self.log_output = log_output
106104
self.start_time = None

papermill/tests/test_engines.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,6 @@ def setUp(self):
3636
self.foo_nb = copy.deepcopy(self.nb)
3737
self.foo_nb.metadata['foo'] = 'bar'
3838

39-
def test_nb_isolation(self):
40-
"""
41-
Tests that the engine notebook is isolated from source notebook
42-
"""
43-
nb_man = NotebookExecutionManager(self.nb)
44-
nb_man.nb.metadata['foo'] = 'bar'
45-
self.assertNotEqual(nb_man.nb, self.nb)
46-
4739
def test_basic_pbar(self):
4840
nb_man = NotebookExecutionManager(self.nb)
4941

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

345337
with patch.object(NotebookExecutionManager, 'save') as save_mock:
346-
nb = CellCallbackEngine.execute_notebook(self.nb, 'python', output_path='foo.ipynb')
338+
nb = CellCallbackEngine.execute_notebook(
339+
copy.deepcopy(self.nb),
340+
'python',
341+
output_path='foo.ipynb'
342+
)
347343

348344
self.assertEqual(nb, AnyMock(NotebookNode))
349345
self.assertNotEqual(self.nb, nb)
@@ -373,7 +369,9 @@ def execute_managed_notebook(cls, nb_man, kernel_name, **kwargs):
373369
with patch.object(NotebookExecutionManager, 'save') as save_mock:
374370
with patch.object(NotebookExecutionManager, 'complete_pbar') as pbar_comp_mock:
375371
nb = NoCellCallbackEngine.execute_notebook(
376-
self.nb, 'python', output_path='foo.ipynb'
372+
copy.deepcopy(self.nb),
373+
'python',
374+
output_path='foo.ipynb'
377375
)
378376

379377
self.assertEqual(nb, AnyMock(NotebookNode))
@@ -407,7 +405,7 @@ def test_nb_convert_engine(self):
407405
with patch.object(engines, 'PapermillNotebookClient') as client_mock:
408406
with patch.object(NotebookExecutionManager, 'save') as save_mock:
409407
nb = NBClientEngine.execute_notebook(
410-
self.nb,
408+
copy.deepcopy(self.nb),
411409
'python',
412410
output_path='foo.ipynb',
413411
progress_bar=False,

0 commit comments

Comments
 (0)