You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
bug: a repeated CSV or TSV header label is read as "name.1", not as written #4708
A repeated label in a CSV or TSV header row is not read as the file holds it: Pandas makes repeated labels unique while reading the header, so the second name comes out as name.1. A column genuinely named name.1 is renamed too, to name.2. The fabricated label appears in the Table element's text and in metadata.text_as_html.
This is the same class of cell corruption that #4574 fixed for data cells ("each cell is read as the text the file holds"), but it happens to the header labels, which dtype=str, keep_default_na=False does not reach.
To Reproduce
fromunstructured.partition.csvimportpartition_csvelement=partition_csv("dup.csv", include_header=True)[0] # dup.csv: "name,name,age\nAlice,Bob,30\n"print(element.text)
# -> "name name.1 age Alice Bob 30" (expected "name name age Alice Bob 30")print(element.metadata.text_as_html)
# -> "<table><tr><td>name</td><td>name.1</td><td>age</td></tr>..."element=partition_csv("genuine.csv", include_header=True)[0] # genuine.csv: "name,name,name.1\nAlice,Bob,Cara\n"print(element.text)
# -> "name name.2 name.1 Alice Bob Cara" (expected "name name name.1 Alice Bob Cara")
partition_tsv reads the same way through the shared read_delimited_text(). Repeated header labels occur in real exports (e.g. merged/repeated column heads from spreadsheets and database dumps).
Expected behavior
The header labels in the element text and text_as_html are the labels the file holds. An empty header cell can keep the Unnamed: n label Pandas gives it, which is the current emitted behavior.
Root cause: pd.read_csv() always renames repeated header labels (the mangle_dupe_cols option was removed in pandas 2.0), in both the C and Python engines. The header record is available to read_delimited_text() through the reader's peek_first_non_blank_line(), so the file's actual labels can be restored after the read.
Activity
fix(csv): read a repeated header label as written (Unstructured-IO#4709)