Card conversion crashes on DataFrames with duplicate column labels
Table.from_dataframe raises AttributeError: 'DataFrame' object has no attribute 'dtype' when two columns share a label.
Tested on Linux with Metaflow commit bda5e77 (2.19.41.post1-gitbda5e77), Python 3.10.12 and pandas 2.3.3.
Reproduction:
import pandas as pd
from metaflow.cards import Table
df = pd.DataFrame([[1, 2], [3, 4]], columns=["A", "A"])
Table.from_dataframe(df)
Expected: the table renders, or unsupported data is handled without an uncaught exception. Actual: AttributeError in convert_to_native_type.py:395. Selecting a duplicated column label returns a DataFrame rather than the Series that the converter expects.
A local workflow step calling this function fails with the same error. Default-card creation for an artifact containing this DataFrame also fails to render. Unique column labels and duplicate index values work.
Related #3413 and #3414 address duplicate MultiIndex level names, rather than column labels.
Would you accept a fix for this? I'd like to work on it with a regression test after confirming the scope.
Hi! I've opened PR #3438 to address this issue.
The fix processes DataFrame columns by position using iloc, so duplicate column labels are handled independently. I've also added a regression test covering duplicate labels and table rendering.
The focused tests pass locally (6 passed). Happy to make adjustments if anything needs changing. Thanks!
Hi @dipesh-svg, thanks for the PR! As noted in the issue description, I was hoping to work on this fix after the maintainers confirm the scope. Would you be open to letting me take it on? I understand if you'd prefer to continue with your existing PR.