Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export fails with complex table heading #89

Open
m-rossi opened this issue Aug 8, 2022 · 0 comments · May be fixed by #90
Open

Export fails with complex table heading #89

m-rossi opened this issue Aug 8, 2022 · 0 comments · May be fixed by #90
Assignees
Labels

Comments

@m-rossi
Copy link
Owner

m-rossi commented Aug 8, 2022

Describe the bug
If I try to export a table with a rather complex table heading, for example created by pint_pandas I get an error.

To reproduce
I have a notebook with the following content

import pandas as pd
import numpy as np

df = pd.DataFrame(np.random.randn(6, 4), columns=[list("1122"), list("ABCD")])
df.index.name = "custom-index"
df.columns.names = (None, "unit")

An export fails with the following error

[Application] ERROR | nbconvert failed: Must pass non-zero number of levels/codes
Traceback (most recent call last):
  File "C:\minforge\lib\site-packages\jupyter_server\nbconvert\handlers.py", line 131, in get
    output, resources = await run_sync(
  File "C:\minforge\lib\site-packages\anyio\to_thread.py", line 31, in run_sync
    return await get_asynclib().run_sync_in_worker_thread(
  File "C:\minforge\lib\site-packages\anyio\_backends\_asyncio.py", line 937, in run_sync_in_worker_thread
    return await future
  File "C:\minforge\lib\asyncio\futures.py", line 284, in __await__
    yield self  # This tells Task to wait for completion.
  File "C:\minforge\lib\asyncio\tasks.py", line 304, in __wakeup
    future.result()
  File "C:\minforge\lib\asyncio\futures.py", line 201, in result
    raise self._exception
  File "C:\minforge\lib\site-packages\anyio\_backends\_asyncio.py", line 867, in run
    result = context.run(func, *args)
  File "C:\minforge\lib\site-packages\jupyter_server\nbconvert\handlers.py", line 132, in <lambda>
    lambda: exporter.from_notebook_node(nb, resources=resource_dict)
  File "C:\minforge\lib\site-packages\jupyter_docx_bundler\__init__.py", line 79, in from_notebook_node
    converters.notebookcontent_to_docxbytes(
  File "C:\minforge\lib\site-packages\jupyter_docx_bundler\converters.py", line 262, in notebookcontent_to_docxbytes
    content = preprocess(content, path, handler=handler)
  File "C:\minforge\lib\site-packages\jupyter_docx_bundler\converters.py", line 193, in preprocess
    raise e
  File "C:\minforge\lib\site-packages\jupyter_docx_bundler\converters.py", line 185, in preprocess
    html_to_pandas_table(output['data']['text/html']).to_markdown(),
  File "C:\minforge\lib\site-packages\jupyter_docx_bundler\converters.py", line 94, in html_to_pandas_table
    df.set_index(index_column_names, inplace=True)
  File "C:\minforge\lib\site-packages\pandas\util\_decorators.py", line 311, in wrapper
    return func(*args, **kwargs)
  File "C:\minforge\lib\site-packages\pandas\core\frame.py", line 5555, in set_index
    index = ensure_index_from_sequences(arrays, names)
  File "C:\minforge\lib\site-packages\pandas\core\indexes\base.py", line 6984, in ensure_index_from_sequences
    return MultiIndex.from_arrays(sequences, names=names)
  File "C:\minforge\lib\site-packages\pandas\core\indexes\multi.py", line 493, in from_arrays
    return cls(
  File "C:\minforge\lib\site-packages\pandas\core\indexes\multi.py", line 321, in __new__
    raise ValueError("Must pass non-zero number of levels/codes")
ValueError: Must pass non-zero number of levels/codes

Desktop (please complete the following information):

  • OS: Windows 10
  • Browser: Firefox
  • Pandoc version: 2.13
@m-rossi m-rossi self-assigned this Aug 9, 2022
@m-rossi m-rossi added the bug label Aug 9, 2022
@m-rossi m-rossi added this to the 0.3.5 milestone Aug 9, 2022
m-rossi added a commit that referenced this issue Aug 9, 2022
@m-rossi m-rossi linked a pull request Aug 9, 2022 that will close this issue
2 tasks
@m-rossi m-rossi linked a pull request Aug 9, 2022 that will close this issue
2 tasks
@m-rossi m-rossi removed this from the 0.3.5 milestone Dec 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant