Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(python): raise error when pandas df's some index name duplicates some column name #16023

Closed
wants to merge 5 commits into from
Closed
3 changes: 3 additions & 0 deletions py-polars/polars/_utils/construction/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -1020,6 +1020,9 @@ def pandas_to_pydf(
) -> PyDataFrame:
"""Construct a PyDataFrame from a pandas DataFrame."""
convert_index = include_index and not _pandas_has_default_index(data)
if convert_index and (data.index.name in data.columns):
msg = "cannot convert pandas DataFrame when index name duplicates some column name"
raise ValueError(msg)
piri-p marked this conversation as resolved.
Show resolved Hide resolved
if not convert_index and all(
is_simple_numpy_backed_pandas_series(data[col]) for col in data.columns
):
Expand Down
Loading