{"record":{"id":"de3c28bf4e770858","repo":"pola-rs/polars","slug":"duplicate-column-name-column-info-name","errorCode":null,"errorMessage":"duplicate column name: {column_info.name}","messagePattern":"duplicate column name: (.+?)","errorType":"exception","errorClass":"DuplicateError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/catalog/unity/models.py","lineNumber":85,"sourceCode":"        \"\"\"\n        Get the native polars schema of this table.\n\n        .. warning::\n            This functionality is considered **unstable**. It may be changed\n            at any point without it being considered a breaking change.\n        \"\"\"\n        issue_unstable_warning(\n            \"`get_polars_schema` functionality is considered unstable.\"\n        )\n        if self.columns is None:\n            return None\n\n        schema = Schema()\n\n        for column_info in self.columns:\n            if column_info.name in schema:\n                msg = f\"duplicate column name: {column_info.name}\"\n                raise DuplicateError(msg)\n            schema[column_info.name] = column_info.get_polars_dtype()\n\n        return schema\n\n\n@dataclass\nclass ColumnInfo:\n    \"\"\"Information for a column within a catalog table.\"\"\"\n\n    name: str\n    type_name: str\n    type_text: str\n    type_json: str\n    position: int | None\n    comment: str | None\n    partition_index: int | None\n\n    def get_polars_dtype(self) -> DataType:","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/pola-rs/polars/blob/9b5d73fd00236295624374b075d16b1fe6ec6df9/py-polars/src/polars/catalog/unity/models.py#L67-L103","documentation":"`TableInfo.get_polars_schema()` converts Unity Catalog column metadata into a `pl.Schema`, which is a dict keyed by column name — names must be unique. If the catalog's `columns` list contains the same name twice, the second assignment collides and polars raises `DuplicateError`. This indicates ambiguous/corrupted table metadata on the catalog side, not a polars bug.","triggerScenarios":"Calling `table_info.get_polars_schema()` directly, or `pl.scan_unity_catalog`/`read_unity_catalog` deriving the schema, on a table whose ColumnInfo list has a repeated `name` (including case-collisions the catalog considers distinct).","commonSituations":"Schema-evolution edge cases or manual metadata registration that produced two identical column names; non-Delta foreign tables imported into UC with colliding names; case-sensitive duplicates ('ID' vs 'id') that the source system allowed.","solutions":["Find the duplicate: `names = [c.name for c in table_info.columns]; print([n for n in set(names) if names.count(n) > 1])`.","Fix the table in the catalog: `ALTER TABLE ... RENAME COLUMN` the duplicate, or re-register the table with unique column names.","If the physical files are fine, read them directly with `pl.scan_delta(path, schema=...)` supplying an explicit deduplicated schema."],"exampleFix":"# before\nschema = table_info.get_polars_schema()  # DuplicateError: duplicate column name: 'id'\n\n# after: locate and fix the duplicate in the catalog, or read files with explicit schema\nschema = pl.Schema({\"id\": pl.Int64, \"id_1\": pl.Int64, \"value\": pl.Float64})\nlf = pl.scan_delta(\"s3://bucket/path/to/table\", schema=schema)","handlingStrategy":"validation","validationCode":"from collections import Counter\n\nnames = [c.name for c in table_info.columns or []]\ndupes = [n for n, count in Counter(names).items() if count > 1]\nif dupes:\n    raise ValueError(f\"duplicate columns in catalog metadata: {dupes}\")\nschema = table_info.get_polars_schema()","typeGuard":null,"tryCatchPattern":"from polars.exceptions import DuplicateError\n\ntry:\n    schema = table_info.get_polars_schema()\nexcept DuplicateError as err:\n    names = [c.name for c in table_info.columns]\n    # proceed with files + explicit deduplicated schema\n    schema = pl.Schema({f\"{n}_{i}\" if names[:i].count(n) else n: pl.String for i, n in enumerate(names)})","preventionTips":["Add a uniqueness assertion on column names whenever ingesting third-party table metadata.","Enforce unique column names at registration time in your catalog.","Watch for case-collisions ('ID' vs 'id') when importing from case-sensitive systems."],"tags":["unity-catalog","schema","duplicate-column","polars"],"backgroundTag":"duplicate-column-name","analyzedSha":"9b5d73fd00236295624374b075d16b1fe6ec6df9","analyzedAt":"2026-08-19T12:15:06.350Z","contentChangedAt":"2026-08-19T12:15:06.350Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}