Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Florian Rathgeber <florian.rathgeber@gmail.com>
  • Loading branch information
cjblocker and kynan authored May 2, 2021
1 parent a61d7d9 commit cfa13fb
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions nbstripout/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def get_size(item):
if isinstance(item, str):
return len(item)
elif isinstance(item, list):
return functools.reduce(lambda a, b: a + get_size(b), item, 0)
return sum(get_size(elem) for elem in item)
elif isinstance(item, dict):
return get_size(list(item.values()))
else:
Expand Down Expand Up @@ -121,12 +121,7 @@ def strip_output(nb, keep_output, keep_count, extra_keys='', max_size=0):
cell['outputs'] = []
else:
# otherwise remove outputs larger than max_size
for idx, output in enumerate(cell['outputs']):
if get_size(output) > max_size:
cell['outputs'][idx] = None
elif 'execution_count' in output and not keep_count:
output['execution_count'] = None
cell['outputs'] = [out for out in cell['outputs'] if out is not None]
cell['outputs'] = [output for output in cell['outputs'] if get_size(output) <= max_size]

# If keep_output_this_cell, but not keep_count, strip the counts
# from the output.
Expand Down

0 comments on commit cfa13fb

Please sign in to comment.