Skip to content
Open
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
16 changes: 15 additions & 1 deletion sec_parser/utils/bs4_/table_to_markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,21 @@ def _to_markdown_table(pandas_table: pd.DataFrame) -> str:
)
markdown_lines = pandas_table.to_markdown(index=False).split("\n")
if all_headers_are_digits:
markdown_lines = markdown_lines[2:]
# Strip the auto-generated integer column header row and its separator.
# When a table has no semantic headers, pandas assigns integer column
# names (0, 1, 2, ...). The first data row is the real visual header
# of the SEC filing table, so promote it and add a divider beneath it
# to produce a valid Markdown table.
data_lines = markdown_lines[2:]
if data_lines:
first_row = data_lines[0]
parts = first_row.split("|")
divider = "|" + "|".join(
"-" * max(1, len(p)) for p in parts[1:-1]
) + "|"
markdown_lines = [first_row, divider] + data_lines[1:]
else:
markdown_lines = data_lines
elif "---" in markdown_lines[1]:
markdown_lines[1] = re.sub(r":?---+:?", "---", markdown_lines[1])
return re.sub(
Expand Down