Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _fetch_scraps(self):
"""Returns a dictionary of the data recorded in a notebook."""
scraps = Scraps()
for cell in self.cells:
for output in cell.get("outputs", []):
output_data_scraps = self._extract_output_data_scraps(output)
output_displays = self._extract_output_displays(output)
# Combine displays with data while trying to preserve ordering
output_scraps = Scraps(
[
# Hydrate with output_displays
(
scrap.name,
Scrap(
scrap.name,
scrap.data,
scrap.encoder,
output_displays.get(scrap.name),
),
)
for scrap in output_data_scraps.values()
]
)
for name, display in output_displays.items():
if name not in output_scraps:
def _extract_output_data_scraps(self, output):
output_scraps = Scraps()
for sig, payload in output.get("data", {}).items():
# Backwards compatibility for papermill
scrap = self._extract_papermill_output_data(sig, payload)
if scrap is None and sig.startswith(GLUE_PAYLOAD_PREFIX):
scrap = encoder_registry.decode(payload_to_scrap(payload))
if scrap:
output_scraps[scrap.name] = scrap
return output_scraps
def _fetch_scraps(self):
"""Returns a dictionary of the data recorded in a notebook."""
scraps = Scraps()
for cell in self.cells:
for output in cell.get("outputs", []):
output_data_scraps = self._extract_output_data_scraps(output)
output_displays = self._extract_output_displays(output)
# Combine displays with data while trying to preserve ordering
output_scraps = Scraps(
[
# Hydrate with output_displays
(
scrap.name,
Scrap(
scrap.name,
scrap.data,
scrap.encoder,
def scraps(self):
"""dict: a dictionary of the merged notebook scraps."""
return Scraps(merge_dicts(nb.scraps for nb in self.notebooks))