timeseriesAI / tsai

Time series Timeseries Deep Learning Machine Learning Python Pytorch fastai | State-of-the-art Deep Learning library for Time Series and Sequences in Pytorch / fastai
https://timeseriesai.github.io/tsai/
Apache License 2.0
5.1k stars 639 forks source link

expected str, bytes or os.PathLike object, not NoneType #614

Closed yangtzech closed 1 year ago

yangtzech commented 1 year ago

Hi, I'm trying to contribute to this project. But there is an error in the last cell:

#|eval: false
#|hide
nb_name = get_nb_name()
create_scripts(nb_name)
nbdev_clean(nb_name)

The log is:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
/tmp/ipykernel_2438039/1984457786.py in <module>
      2 #|hide
      3 nb_name = get_nb_name()
----> 4 create_scripts(nb_name)
      5 nbdev_clean(nb_name)

~/yzc/repos/tsai/tsai/imports.py in create_scripts(nb_name, max_elapsed, wait)
    173     from nbdev.clean import nbdev_clean
    174     save_nb(nb_name, wait=wait)
--> 175     full_nb_name = str(Path.cwd()/nb_name)
    176     nb_export(full_nb_name)
    177     output = py_last_saved(nb_name, max_elapsed)

~/anaconda3/envs/tsai_dev/lib/python3.7/pathlib.py in __truediv__(self, key)
    923 
    924     def __truediv__(self, key):
--> 925         return self._make_child((key,))
    926 
    927     def __rtruediv__(self, key):

~/anaconda3/envs/tsai_dev/lib/python3.7/pathlib.py in _make_child(self, args)
    702 
    703     def _make_child(self, args):
...
--> 658                 a = os.fspath(a)
    659                 if isinstance(a, str):
    660                     # Force-cast str subclasses to str (issue #21127)

TypeError: expected str, bytes or os.PathLike object, not NoneType

It seems the ‘nb_name‘ is None

yangtzech commented 1 year ago

Switch from VSCode notebook to Jupyter notebook and after several times of *.ipynb couldn't be saved, finally it is saved and exported.

oguiza commented 1 year ago

Hi @yangtzech, It's great to hear you want to contribute to tsai. I've looked into the issue and have created a fix. I've updated (and simplified) the code to save the nb and convert the nb to a script. Now you only need to use:

#|eval: false
#|hide
from tsai.export import get_nb_name; nb_name = get_nb_name(locals())
from tsai.imports import create_scripts; create_scripts(nb_name)

I've tested the new approach both in Jupyter notebook and in VSCode and it worked well. It'd be good if you could test it as well.

yangtzech commented 1 year ago

I have tested it both in VSCode and Jupyter Notebook. It works fine for me. Thanks!