nteract / scrapbook

A library for recording and reading data in notebooks.
https://nteract-scrapbook.readthedocs.io
BSD 3-Clause "New" or "Revised" License
281 stars 26 forks source link

Not being able to extract scraps #41

Closed WhoAteDaCake closed 5 years ago

WhoAteDaCake commented 5 years ago

Hello, I am trying to extract data after using papermill. I have multiple values within the notebook, but none of them are visible.

My script

import papermill as pm
import os
import scrapbook as sb

# Set up files
dir_name = os.path.dirname(os.path.realpath(__file__))
input = os.path.join(dir_name, "test.ipynb")
output = os.path.join(dir_name, "out.ipynb")

# Inject notebook settings
# pm.execute_notebook(
#     input,
#     output,
#     parameters=dict(msg="Bye")
# )

# Import scraps
# sb.glue("result", "world")
nb = sb.read_notebook(output)
# Extract parameters
print(nb.scrap_dataframe)
nb.reglue("result")
# print(nb.scraps.data_dict)

# Clean up not needed, because notebook will just be overriden

And this is the link to the notebook i ran output.ipynb https://pastebin.com/raw/mC0ybwy5

WhoAteDaCake commented 5 years ago

print(nb.scrap_dataframe) returns an empty array, even though i have variables like msg, result, result2

MSeal commented 5 years ago

Thanks for posting the notebook file. I'll look into the issue tonight and see what's causing the issue.

MSeal commented 5 years ago

So after reading the notebook, the way you're using the API isn't quite right. Scrapbook isn't reading the printed result of each cell execution. You have to use the sb.glue("result", "world") inside the notebook. Then the scap_dataframe outside of the notebook in your script file will include a row with a name of "result" and a value of "world"

WhoAteDaCake commented 5 years ago

Thank you that makes more sense. However when i try to use sb.glue("result", "world") I get an error saying:

AttributeError: module 'scrapbook' has no attribute 'glue' The same issue occurs when reading a notebook

I've installed scrapbook using pip install nteract-scrapbook[all]

Edit: It worked by using

from scrapbook.api import glue
glue("result", result)
mansiparashar commented 4 years ago

Hi, the above solution is not working for me. I get the errors AttributeError: module 'scrapbook' has no attribute 'glue' and then for the solution AttributeError: module 'scrapbook' has no attribute 'api'

MSeal commented 4 years ago

Do you have a local file named scrapbook.py? This can make Python think that is the module you are importing instead of the installed package.

mansiparashar commented 4 years ago

Do you have a local file named scrapbook.py? This can make Python think that is the module you are importing instead of the installed package.

No, no such file

mansiparashar commented 4 years ago

Do you have a local file named scrapbook.py? This can make Python think that is the module you are importing instead of the installed package.

No, no such file

MSeal commented 4 years ago

You'll need to figure out what is installed in place of scrapbook's name. Check that scrapbook is actually installed pip freeze | grep scrapbook and is the latest version. My guess is you have something else overloading the scrapbook import name or a really old version installed.