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
Duplicate columns are silently accepted from files and give unclear errors from DataFrames #653
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:
importioimportpandasaspdfrompetab.v2importCfrompetab.v2.coreimportConditionTablecols= [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 labelsConditionTable.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.
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.
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
Activity
dweindl commentedon Dec 1, 2026
v1 is affected as well (tested on
main, 4add899, withdoc/example/example_Fujita, duplicating one column at a time):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 duplicateEGFgivesCondition table contains column for unknown entity 'EGF.1', and a duplicateconditionIdgivesMissing parameter(s) in the model or the parameters table: {'model1_data2', ...}.lint_problemcrashes withAttributeError: 'DataFrame' object has no attribute 'dtype'(or'unique') incheck_measurement_df,check_observable_df,check_parameter_df, andassert_placeholders_only_used_in_own_observable, sincedf[column]returns a DataFrame and onlyAssertionErroris caught.The same approach would apply: check the raw header in the
get_*_dfreaders and checkdf.columns.is_unique(including the index name) in_check_df.🤖 Drafted with AI assistance (Claude Code).
[-]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[/+]