{"record":{"id":"1021cb4d6f6fda46","repo":"apache/beam","slug":"encountered-an-index-that-has-the-same-name-as-one-of-the","errorCode":null,"errorMessage":"Encountered an index that has the same name as one of the columns, '%s'. Cannot convert to a schema-aware PCollection with include_indexes=True. Please ensure all indexes have unique names or consider not including indexes.","messagePattern":"Encountered an index that has the same name as one of the columns, '(.+?)'\\. Cannot convert to a schema-aware PCollection with include_indexes=True\\. Please ensure all indexes have unique names or consider not including indexes\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/dataframe/schemas.py","lineNumber":155,"sourceCode":"  if include_indexes:\n    remaining_index_names = list(proxy.index.names)\n    i = 0\n    while len(remaining_index_names):\n      index_name = remaining_index_names.pop(0)\n      if index_name is None:\n        raise ValueError(\n            \"Encountered an unnamed index. Cannot convert to a \"\n            \"schema-aware PCollection with include_indexes=True. \"\n            \"Please name all indexes or consider not including \"\n            \"indexes.\")\n      elif index_name in remaining_index_names:\n        raise ValueError(\n            \"Encountered multiple indexes with the name '%s'. \"\n            \"Cannot convert to a schema-aware PCollection with \"\n            \"include_indexes=True. Please ensure all indexes have \"\n            \"unique names or consider not including indexes.\" % index_name)\n      elif index_name in proxy.columns:\n        raise ValueError(\n            \"Encountered an index that has the same name as one \"\n            \"of the columns, '%s'. Cannot convert to a \"\n            \"schema-aware PCollection with include_indexes=True. \"\n            \"Please ensure all indexes have unique names or \"\n            \"consider not including indexes.\" % index_name)\n      else:\n        # its ok!\n        output_columns.append(\n            (index_name, proxy.index.get_level_values(i).dtype))\n        i += 1\n\n  output_columns.extend(zip(proxy.columns, proxy.dtypes))\n\n  fields = [(column, dtype_to_fieldtype(dtype))\n            for (column, dtype) in output_columns]\n  field_options: Optional[dict[str, Sequence[tuple[str, Any]]]]\n  if include_indexes:\n    field_options = {","sourceCodeStart":137,"sourceCodeEnd":173,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/dataframe/schemas.py#L137-L173","documentation":"With include_indexes=True, both index levels and columns become schema fields, so an index name equal to a column name would produce a duplicate field. ValueError is raised naming the conflicting identifier.","triggerScenarios":"Converting to a schema-aware PCollection with include_indexes=True where df.index.name equals one of df.columns (e.g. index named 'id' and a column 'id').","commonSituations":"reset_index-style workflows where the index kept the column's name; joins/groupbys on a key column that also became the index.","solutions":["Rename the index (df.index.name = 'index_id') so it differs from all column names","Drop the index from inclusion with include_indexes=False, or reset_index(drop=True)","Remove/rename the conflicting column before conversion"],"exampleFix":"// before\ndf.index.name = 'id'; df['id'] = ...\n// after\ndf.index.name = 'row_index'  # distinct from column 'id'","handlingStrategy":"validation","validationCode":"if include_indexes and proxy.index.name is not None and proxy.index.name in proxy.columns:\n    proxy.index.name = proxy.index.name + '_index'  # avoid collision with column field","typeGuard":"def index_names_disjoint_from_columns(df) -> bool:\n    return all(n is None or n not in df.columns for n in df.index.names)","tryCatchPattern":"try:\n    pc = beam.dataframe.convert.to_pcollection(df, include_indexes=True)\nexcept ValueError as e:\n    if 'same name as one of the columns' in str(e):\n        df.index.name = f'{df.index.name}_index'\n        pc = beam.dataframe.convert.to_pcollection(df, include_indexes=True)","preventionTips":["Keep index names distinct from column names by convention (e.g. suffix '_index')","Run a name-collision check before any include_indexes=True conversion","Consider reset_index() and unique column names as the canonical schema"],"tags":["python","apache-beam","dataframe","schema","index"],"backgroundTag":"schema-validation-failed","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}