Skip to content

Duplicate columns are silently accepted from files and give unclear errors from DataFrames #653

Backlog

Description

@dweindl

Duplicate column names in v2 tables are not handled consistently (tested on main, 4add899):

  • From TSV files, duplicates are silently accepted for all tables except the mapping table. pandas.read_csv renames a duplicate header to, e.g., conditionId.1. Since the table models allow extra fields, that column is kept as an extra column (and written back as conditionId.1), and the value from the first column is used. petablint doesn't report anything.

  • From DataFrames, _records raises ValueError: Duplicate column(s): ..., but some tables fail earlier with errors that don't mention the duplicate column:

    Table Duplicate column Error
    condition conditionId ValueError: cannot reindex on an axis with duplicate labels
    experiment experimentId ValueError: Grouper for 'experimentId' not 1-dimensional
    experiment time AttributeError: 'DataFrame' object has no attribute 'unique'
    observable observableId pydantic ValidationError for Observable
    mapping (from TSV) any pydantic ValidationError for Mapping

Reproduction:

import io
import pandas as pd
from petab.v2 import C
from petab.v2.core import ConditionTable

cols = [C.CONDITION_ID, C.TARGET_ID, C.TARGET_VALUE, C.CONDITION_ID]
df = pd.DataFrame([["c1", "k", 1, "c2"]], columns=cols)

# ValueError: cannot reindex on an axis with duplicate labels
ConditionTable.from_df(df)

# accepted, with an extra column `conditionId.1`
tsv = io.StringIO(df.to_csv(sep="\t", index=False))
ConditionTable.from_df(pd.read_csv(tsv, sep="\t"))

Possible approach:

  • In from_tsv, check the raw header for duplicates before pandas renames them (mangle_dupe_cols was removed in pandas 2.0, so this needs a separate read of the header, e.g., pd.read_csv(..., header=None, nrows=1)).
  • In BaseTable.from_df, check df.columns.is_unique after moving named index levels to columns, i.e., before the table-specific code runs, and raise an error naming the table, the duplicate columns, and the file, analogous to MissingColumnsError (v2: check for missing required columns when loading tables #610). This would make the check in _records redundant for table loading.

Relates to #369, #611.

🤖 Drafted with AI assistance (Claude Code).

Activity

  1. dweindl commented on Dec 1, 2026

    @dweindl
    MemberAuthor

    v1 is affected as well (tested on main, 4add899, with doc/example/example_Fujita, duplicating one column at a time):

    • From files, duplicates in the measurement, observable, and parameter tables are silently accepted by petablint (tested: observableId, simulationConditionId, measurement, time, observableFormula, noiseFormula, parameterId, estimate). In the condition table, the renamed column is treated as a model entity, so a duplicate EGF gives Condition table contains column for unknown entity 'EGF.1', and a duplicate conditionId gives Missing parameter(s) in the model or the parameters table: {'model1_data2', ...}.
    • From DataFrames, lint_problem crashes with AttributeError: 'DataFrame' object has no attribute 'dtype' (or 'unique') in check_measurement_df, check_observable_df, check_parameter_df, and assert_placeholders_only_used_in_own_observable, since df[column] returns a DataFrame and only AssertionError is caught.

    The same approach would apply: check the raw header in the get_*_df readers and check df.columns.is_unique (including the index name) in _check_df.

    🤖 Drafted with AI assistance (Claude Code).

  2. changed the title [-]v2: duplicate columns are silently accepted from files and give unclear errors from DataFrames[/-] [+]Duplicate columns are silently accepted from files and give unclear errors from DataFrames[/+] on Dec 1, 2026
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