Skip to content

bug: a repeated CSV or TSV header label is read as "name.1", not as written #4708

Closed

Description

@Bensonluo

Describe the bug

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

from unstructured.partition.csv import partition_csv

element = 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.

Environment Info

unstructured 0.27.38-dev (main c47ef65), pandas 2.3.3, Python 3.12, macOS arm64.

Additional context

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

  1. added a commit that references this issue on Nov 13, 2026
    7d81b40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions