Skip to content

Commit

Permalink
make duplicate column check optimistic
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-beedie committed Jan 9, 2025
1 parent 8995e81 commit 976eb19
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions py-polars/polars/_utils/construction/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -1171,12 +1171,6 @@ def arrow_to_pydf(
msg = "dimensions of columns arg must match data dimensions"
raise ValueError(msg) from e

# arrow tables allow duplicate names; we don't
if len(column_names) != len(set(column_names)):
col_name, col_count = Counter(column_names).most_common(1)[0]
msg = f"column {col_name!r} appears {col_count} times; names must be unique"
raise DuplicateError(msg)

batches: list[pa.RecordBatch]
if isinstance(data, pa.RecordBatch):
batches = [data]
Expand All @@ -1186,6 +1180,12 @@ def arrow_to_pydf(
# supply the arrow schema so the metadata is intact
pydf = PyDataFrame.from_arrow_record_batches(batches, data.schema)

# arrow tables allow duplicate names; we don't
if len(data.columns) != pydf.width():
col_name, col_count = Counter(column_names).most_common(1)[0]
msg = f"column {col_name!r} appears {col_count} times; names must be unique"
raise DuplicateError(msg)

if rechunk:
pydf = pydf.rechunk()

Expand Down

0 comments on commit 976eb19

Please sign in to comment.