Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/chonkie/utils/table_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ def _read_markdown_table(table_content: str):
) from e

lines = [line.strip("|").strip() for line in table_content.split("\n") if line.strip()]
if len(lines) < 2:
# Empty/blank headers (incl. multi-col "| | | |") yield EmptyDataError from pandas.
if len(lines) < 2 or not lines[0].replace("|", "").strip():
return pd.DataFrame()

csv_content = "\n".join([lines[0]] + lines[2:])
Expand Down
6 changes: 6 additions & 0 deletions tests/test_table_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ def test_empty_table(self) -> None:
"""Test empty and header-only tables."""
assert markdown_table_to_json("") == []
assert markdown_table_to_json("| Name |\n|------|") == []
# Empty header cells must not leak pandas EmptyDataError.
assert markdown_table_to_json("|\n|-|") == []
assert markdown_table_to_json("||\n|-|") == []
# strip("|") leaves inner pipes for 3+ blank columns; still empty JSON.
assert markdown_table_to_json("| | | |\n|---|---|---|") == []
assert markdown_table_to_json("| | | | |\n|---|---|---|---|") == []


class TestHTMLTableToJson:
Expand Down