{"record":{"id":"664d6cb0d581c78e","repo":"apache/beam","slug":"encountered-multiple-indexes-with-the-name-s-cannot-convert","errorCode":null,"errorMessage":"Encountered multiple indexes with the name '%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 multiple indexes with the name '(.+?)'\\. 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":149,"sourceCode":"\n\ndef element_typehint_from_dataframe_proxy(\n    proxy: pd.DataFrame, include_indexes: bool = False) -> RowTypeConstraint:\n\n  output_columns = []\n  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))","sourceCodeStart":131,"sourceCodeEnd":167,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/dataframe/schemas.py#L131-L167","documentation":"With include_indexes=True, index levels become schema fields, so their names must be unique. If two index levels share the same name, the schema would contain duplicate field names, and ValueError is raised listing the duplicated name.","triggerScenarios":"Converting a DataFrame with a MultiIndex where two levels have identical names, using include_indexes=True via element_typehint_from_dataframe_proxy / to_pcollection.","commonSituations":"MultiIndexes built from reset/index operations where levels kept the same source column name (e.g. groupby on the same column twice).","solutions":["Rename the duplicate index levels to unique names (df.index.names = ['l1','l2', ...])","Drop redundant levels via df.droplevel(i) if they duplicate information","Use reset_index() to flatten the index and disambiguate column names, then convert without include_indexes"],"exampleFix":"// before\ndf.index.names = ['id', 'id']\n// after\ndf.index.names = ['id_level_1', 'id_level_2']","handlingStrategy":"validation","validationCode":"names = [n for n in proxy.index.names if n is not None]\nif len(names) != len(set(names)):\n    dupes = {n for n in names if names.count(n) > 1}\n    raise ValueError(f'Duplicate index names: {dupes}; rename before include_indexes=True')","typeGuard":"def has_unique_index_names(df) -> bool:\n    names = [n for n in df.index.names if n is not None]\n    return len(names) == len(set(names))","tryCatchPattern":"try:\n    pc = beam.dataframe.convert.to_pcollection(df, include_indexes=True)\nexcept ValueError as e:\n    if 'multiple indexes with the name' in str(e):\n        df.index.names = [f'index_{i}_{n}' for i, n in enumerate(df.index.names)]\n        pc = beam.dataframe.convert.to_pcollection(df, include_indexes=True)","preventionTips":["Make MultiIndex level names unique at construction time","Droplevel redundant duplicate levels before conversion","Add a pre-conversion uniqueness assertion on index.names"],"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"}