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
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ def convert(
reader = csv.reader(io.StringIO(content))
rows = list(reader)

# Skip leading empty rows
start_idx = 0
while start_idx < len(rows) and (
not rows[start_idx] or all(cell.strip() == "" for cell in rows[start_idx])
):
start_idx += 1
rows = rows[start_idx:]

if not rows:
return DocumentConverterResult(markdown="")

Expand Down
16 changes: 16 additions & 0 deletions packages/markitdown/tests/test_module_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,21 @@ def test_markitdown_llm() -> None:
validate_strings(result, PPTX_TEST_STRINGS)


def test_csv_with_blank_first_line() -> None:
markitdown = MarkItDown()
csv_content = "\n\nname,age\nbob,3\nalice,7\n"
result = markitdown.convert_stream(
io.BytesIO(csv_content.encode("utf-8")),
file_extension=".csv",
)
assert "name" in result.text_content
assert "age" in result.text_content
assert "bob" in result.text_content
assert "3" in result.text_content
assert "alice" in result.text_content
assert "7" in result.text_content


if __name__ == "__main__":
"""Runs this file's tests from the command line."""
for test in [
Expand All @@ -547,6 +562,7 @@ def test_markitdown_llm() -> None:
test_markitdown_exiftool,
test_markitdown_llm_parameters,
test_markitdown_llm,
test_csv_with_blank_first_line,
]:
print(f"Running {test.__name__}...", end="")
test()
Expand Down