Skip to content

fix: return empty JSON for markdown tables with blank headers - #638

Open
santhreal wants to merge 2 commits into
feyninc:mainfrom
santhreal:fix/markdown-table-empty-columns
Open

fix: return empty JSON for markdown tables with blank headers#638
santhreal wants to merge 2 commits into
feyninc:mainfrom
santhreal:fix/markdown-table-empty-columns

Conversation

@santhreal

@santhreal santhreal commented Jul 18, 2026

Copy link
Copy Markdown

markdown_table_to_json hits EmptyDataError when |\n|-|. This PR fixes the regression with a focused test covering the case.

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of Markdown tables when the header row contains no meaningful text.
    • Converting header-only or effectively empty/malformed Markdown tables to JSON now returns an empty list (with no errors).

Blank header cells produced an empty CSV for pandas and leaked EmptyDataError from markdown_table_to_json.
@coderabbitai

coderabbitai Bot commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 2c2a313d-bc20-4a89-aee3-4c8c7c85ec01

📥 Commits

Reviewing files that changed from the base of the PR and between 42ee078 and a21b757.

📒 Files selected for processing (2)
  • src/chonkie/utils/table_converter.py
  • tests/test_table_converter.py
🚧 Files skipped from review as they are similar to previous changes (2)
  • tests/test_table_converter.py
  • src/chonkie/utils/table_converter.py

📝 Walkthrough

Walkthrough

The table converter now treats Markdown tables with empty or blank header rows as empty data and returns an empty JSON list. Tests cover single-cell, empty-cell, and multi-column blank-header formats.

Changes

Empty Markdown Table Handling

Layer / File(s) Summary
Guard empty headers and validate empty results
src/chonkie/utils/table_converter.py, tests/test_table_converter.py
_read_markdown_table returns an empty DataFrame when the first parsed line has no meaningful header content. Tests verify empty JSON results for several empty-header formats.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Poem

A rabbit found a table bare,
With empty headers floating there.
“No rows to parse,” it softly said,
And hopped away with tests well fed.
🐇

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main fix for markdown tables with blank headers returning empty JSON.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request aims to prevent pandas EmptyDataError when parsing markdown tables with empty header cells by returning an empty DataFrame, and adds corresponding test cases. The review feedback correctly points out that the proposed check not lines[0] is insufficient for tables with three or more empty columns because strip("|") only removes leading and trailing pipes, and suggests a more robust check to handle these cases.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread src/chonkie/utils/table_converter.py Outdated
Comment on lines 18 to 19
if len(lines) < 2 or not lines[0]:
return pd.DataFrame()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The current check 'not lines[0]' only detects empty headers for tables with 1 or 2 columns. For tables with 3 or more columns (e.g., '| | | |'), 'lines[0]' will be evaluated as '|' (or containing multiple pipes) because 'strip("|")' only removes the leading and trailing pipes. As a result, 'not lines[0]' evaluates to False, and the function will still attempt to parse the table and return non-empty JSON with 'Unnamed' keys, which contradicts the PR's objective of returning empty JSON for tables with blank headers.\n\nTo ensure consistent behavior across any number of columns, we should check if the header line contains only pipes and whitespace.

    if len(lines) < 2 or not lines[0].replace('|', '').strip():\n        return pd.DataFrame()

strip("|") only clears leading/trailing pipes, so "| | | |" still looked non-empty and produced Unnamed columns.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant