diff --git a/src/chonkie/utils/table_converter.py b/src/chonkie/utils/table_converter.py index c5bb56a2..31b21207 100644 --- a/src/chonkie/utils/table_converter.py +++ b/src/chonkie/utils/table_converter.py @@ -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:]) diff --git a/tests/test_table_converter.py b/tests/test_table_converter.py index c34e74c4..5ead6871 100644 --- a/tests/test_table_converter.py +++ b/tests/test_table_converter.py @@ -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: