bab2min / tomotopy

Python package of Tomoto, the Topic Modeling Tool
https://bab2min.github.io/tomotopy
MIT License
548 stars 62 forks source link

add_doc with an invalid doc -> crash jupyter kernel #187

Open rmalouf opened 1 year ago

rmalouf commented 1 year ago

Running tomotopy (0.12.3) in a jupyter notebook. Calling LDAModel.add_doc with an invalid document, e.g.:

mdl.add_doc([['a', 'b']])

or

mdl.add_doc([[1, 2]])

crashes the kernel. Here's what I think is the relevant part of the traceback:

Error in sys.excepthook:
Traceback (most recent call last):
  File "/opt/conda/lib/python3.10/site-packages/ipykernel/kernelapp.py", line 202, in excepthook
    traceback.print_exception(etype, evalue, tb, file=sys.__stderr__)
  File "/opt/conda/lib/python3.10/traceback.py", line 119, in print_exception
    te = TracebackException(type(value), value, tb, limit=limit, compact=True)
  File "/opt/conda/lib/python3.10/traceback.py", line 536, in __init__
    e.__cause__.__traceback__,
AttributeError: 'str' object has no attribute '__traceback__'

Original exception was:
TypeError: print_exception(): Exception expected for value, str found

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/opt/conda/lib/python3.10/site-packages/IPython/core/interactiveshell.py", line 3398, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "/tmp/ipykernel_274773/1810559270.py", line 1, in <cell line: 1>
ValueError: cannot convert 1 into appropriate C++ type

If I try the same thing in a normal python interpreter, I get the error:

TypeError: print_exception(): Exception expected for value, str found

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: cannot convert 1 into appropriate C++ type

with no crash.

bab2min commented 1 year ago

Hi @rmalouf Thank you for reporting the bug. The exception throwing mechanism of 0.12.3 seems not to work with Jupyter. I'll examine it.