{"record":{"id":"d3a1de444f030e2a","repo":"apache/beam","slug":"set-index-with-index-or-series-instances-is-not-yet","errorCode":null,"errorMessage":"set_index with Index or Series instances is not yet supported (https://github.com/apache/beam/issues/20759).","messagePattern":"set_index with Index or Series instances is not yet supported \\(https://github\\.com/apache/beam/issues/20759\\)\\.","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/dataframe/frames.py","lineNumber":2677,"sourceCode":"    if key in self.columns:\n      return self[key]\n    else:\n      return default_value\n\n  @frame_base.with_docs_from(pd.DataFrame)\n  @frame_base.args_to_kwargs(pd.DataFrame)\n  @frame_base.populate_defaults(pd.DataFrame)\n  @frame_base.maybe_inplace\n  def set_index(self, keys, **kwargs):\n    \"\"\"``keys`` must be a ``str`` or ``list[str]``. Passing an Index or Series\n    is not yet supported (`Issue 20759\n    <https://github.com/apache/beam/issues/20759>`_).\"\"\"\n    if isinstance(keys, str):\n      keys = [keys]\n\n    if any(isinstance(k, (_DeferredIndex, frame_base.DeferredFrame))\n           for k in keys):\n      raise NotImplementedError(\"set_index with Index or Series instances is \"\n                                \"not yet supported \"\n                                \"(https://github.com/apache/beam/issues/20759)\"\n                                \".\")\n\n    return frame_base.DeferredFrame.wrap(\n      expressions.ComputedExpression(\n          'set_index',\n          lambda df: df.set_index(keys, **kwargs),\n          [self._expr],\n          requires_partition_by=partitionings.Arbitrary(),\n          preserves_partition_by=partitionings.Singleton()))\n\n\n  @frame_base.with_docs_from(pd.DataFrame)\n  @frame_base.args_to_kwargs(pd.DataFrame)\n  @frame_base.populate_defaults(\n      pd.DataFrame,\n      removed_args=['inplace'] if PD_VERSION >= (2, 0) else None)","sourceCodeStart":2659,"sourceCodeEnd":2695,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/dataframe/frames.py#L2659-L2695","documentation":"DeferredDataFrame.set_index supports only column names (strings) as keys. Passing a pandas Index/Series-like value as a DeferredIndex or DeferredFrame key is not yet implemented (tracked in apache/beam issue #20759) because it is generally order-sensitive in a distributed setting, so a NotImplementedError is raised.","triggerScenarios":"df.set_index(df['col']) (passing a deferred Series instead of the name 'col'); df.set_index(pd.Index([...])) or df.set_index(other_df.index).","commonSituations":"Porting pandas code that builds indexes from Series objects; dynamically constructed indexes in pipelines migrated to apache_beam.dataframe.","solutions":["Pass the column name string instead of the Series: df.set_index('col') rather than df.set_index(df['col']).","Pass a list of column-name strings for a MultiIndex: df.set_index(['a', 'b']).","Materialize the desired index into a column first (df['idx'] = ...), then set_index('idx').","Convert to plain pandas for this step if a Series-based index is unavoidable."],"exampleFix":"// before\ndf = df.set_index(df['user_id'])\n// after\ndf = df.set_index('user_id')","handlingStrategy":"type-guard","validationCode":"if isinstance(keys, (DeferredIndex, DeferredFrame)) or any(isinstance(k, (DeferredIndex, DeferredFrame)) for k in (keys if isinstance(keys, list) else [keys])):\n    raise TypeError('use column name strings with set_index')","typeGuard":"def is_valid_set_index_keys(keys) -> bool:\n    keys = [keys] if isinstance(keys, str) else keys\n    return all(isinstance(k, str) and not isinstance(k, (DeferredIndex, DeferredFrame)) for k in keys)","tryCatchPattern":"try:\n    df = df.set_index(keys)\nexcept NotImplementedError:\n    df = df.set_index('col_name')","preventionTips":["Pass column name strings, never df['col'] Series objects, to set_index.","Track apache/beam issue #20759 for the feature landing.","Materialize computed indexes into a column first.","Review pandas code for Series-based set_index before Beam migration."],"tags":["python","apache-beam","dataframe","set-index","not-implemented"],"backgroundTag":"unsupported-operation","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"}