{"record":{"id":"d4d7899ec57129cf","repo":"apache/beam","slug":"assigning-an-index-is-not-yet-supported-consider-using-set","errorCode":null,"errorMessage":"Assigning an index is not yet supported. Consider using set_index() instead.","messagePattern":"Assigning an index is not yet supported\\. Consider using set_index\\(\\) instead\\.","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/dataframe/frames.py","lineNumber":1201,"sourceCode":"          \"on the full dataset.\"),\n      preserves_partition_by=expressions.partitionings.Singleton())\n\n  @property  # type: ignore\n  @frame_base.with_docs_from(pd.DataFrame)\n  def ndim(self):\n    return self._expr.proxy().ndim\n\n  @property  # type: ignore\n  @frame_base.with_docs_from(pd.DataFrame)\n  def index(self):\n    return _DeferredIndex(self)\n\n  @index.setter\n  def _set_index(self, value):\n    # TODO: assigning the index is generally order-sensitive, but we could\n    # support it in some rare cases, e.g. when assigning the index from one\n    # of a DataFrame's columns\n    raise NotImplementedError(\n        \"Assigning an index is not yet supported. \"\n        \"Consider using set_index() instead.\")\n\n  reindex = frame_base.wont_implement_method(\n      pd.DataFrame, 'reindex', reason=\"order-sensitive\")\n\n  hist = frame_base.wont_implement_method(\n      pd.DataFrame, 'hist', reason=\"plotting-tools\")\n\n  attrs = property(\n      fget=frame_base.wont_implement_method(\n          pd.DataFrame, 'attrs', reason='experimental'),\n      fset=frame_base.wont_implement_method(\n          pd.DataFrame, 'attrs', reason='experimental'),\n  )\n\n  reorder_levels = frame_base._proxy_method(\n      'reorder_levels',","sourceCodeStart":1183,"sourceCodeEnd":1219,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/dataframe/frames.py#L1183-L1219","documentation":"Assigning to the .index attribute of a Beam DeferredFrame (df.index = ...) is an order-sensitive operation the distributed implementation cannot support, so the index setter raises NotImplementedError and points to set_index().","triggerScenarios":"Writing df.index = new_index or df.index = df['col'] on a Beam DataFrame; assigning index inside a pipeline transformation.","commonSituations":"Direct pandas ports that reassign the index; attempts to overwrite the index with a column; migrations where pandas code did df.index = pd.RangeIndex(...).","solutions":["Use df.set_index('col') to build the index from a column","Use reset_index(drop=True) to replace the index instead of assigning","Convert to pandas (df.to_pandas()) only if the data fits in memory, then assign"],"exampleFix":"// before\ndf.index = df['id']\n// after\ndf = df.set_index('id')","handlingStrategy":"fallback","validationCode":"# avoid the pattern entirely\nassert not isinstance(value, pd.Index) or True  # never do: df.index = value","typeGuard":null,"tryCatchPattern":"try:\n    df.index = new_index\nexcept NotImplementedError:\n    df = df.set_index(new_index.name) if hasattr(new_index, 'name') else df.reset_index(drop=True)","preventionTips":["Never assign to .index on DeferredFrames","Use set_index()/reset_index() exclusively","Grep for '.index =' when porting pandas code to Beam"],"tags":["python","apache-beam","dataframe","not-implemented","order-sensitive"],"backgroundTag":"method-not-implemented","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"}