{"record":{"id":"f54994d608593741","repo":"apache/beam","slug":"using-iloc-to-mutate-a-frame-is-not-supported-because-it-s","errorCode":null,"errorMessage":"Using iloc to mutate a frame is not supported because it's position-based indexing is sensitive to the order of the data.","messagePattern":"Using iloc to mutate a frame is not supported because it's position-based indexing is sensitive to the order of the data\\.","errorType":"exception","errorClass":"WontImplementError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/dataframe/frames.py","lineNumber":5005,"sourceCode":"        raise frame_base.WontImplementError(\n            \"Using iloc to select rows is not supported because it's \"\n            \"position-based indexing is sensitive to the order of the data.\",\n            reason=\"order-sensitive\")\n      return frame_base.DeferredFrame.wrap(\n          expressions.ComputedExpression(\n              'iloc',\n              lambda df: df.iloc[index],\n              [self._frame._expr],\n              requires_partition_by=partitionings.Arbitrary(),\n              preserves_partition_by=partitionings.Arbitrary()))\n    else:\n      raise frame_base.WontImplementError(\n          \"Using iloc to select rows is not supported because it's \"\n          \"position-based indexing is sensitive to the order of the data.\",\n          reason=\"order-sensitive\")\n\n  def __setitem__(self, index, value):\n    raise frame_base.WontImplementError(\n        \"Using iloc to mutate a frame is not supported because it's \"\n        \"position-based indexing is sensitive to the order of the data.\",\n        reason=\"order-sensitive\")\n\n\nclass _DeferredStringMethods(frame_base.DeferredBase):\n  @frame_base.with_docs_from(pd.Series.str)\n  @frame_base.args_to_kwargs(pd.Series.str)\n  @frame_base.populate_defaults(pd.Series.str)\n  def cat(self, others, join, **kwargs):\n    \"\"\"If defined, ``others`` must be a :class:`DeferredSeries` or a ``list`` of\n    ``DeferredSeries``.\"\"\"\n    if others is None:\n      # Concatenate series into a single String\n      requires = partitionings.Singleton(reason=(\n          \"cat(others=None) concatenates all data in a Series into a single \"\n          \"string, so it requires collecting all data on a single node.\"\n      ))","sourceCodeStart":4987,"sourceCodeEnd":5023,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/dataframe/frames.py#L4987-L5023","documentation":"iloc.__setitem__ unconditionally raises WontImplementError. Assigning through position-based indexing would need to know which physical row each element lands in, which is order-sensitive and cannot be deferred in Beam's distributed model.","triggerScenarios":"Any assignment via the iloc indexer on a deferred Beam DataFrame, e.g. df.iloc[0, 'a'] = 5 or df.iloc[:, 0] = value.","commonSituations":"Translating pandas mutation code (setting a cell by position) into Beam; data-fixup scripts written for pandas; in-place edits during interactive exploration.","solutions":["Use column-wise assignment instead: df['a'] = new_values (vectorized, order-independent).","Assign via .loc with explicit index labels if the index is well-defined.","Compute the new column with an expression and wrap it with df as a whole rather than mutating cells.","Do positional mutations in plain pandas outside the Beam pipeline."],"exampleFix":"// before\ndf.iloc[:, 0] = df.iloc[:, 0] * 2\n\n// after\ndf[df.columns[0]] = df[df.columns[0]] * 2","handlingStrategy":"validation","validationCode":"if isinstance(indexer, type(df).iloc.__class__):\n    raise ValueError(\"do not mutate via iloc in Beam dataframes\")","typeGuard":null,"tryCatchPattern":"try:\n    df.iloc[:, 0] = values\nexcept apachebeam.WontImplementError:\n    df[df.columns[0]] = values","preventionTips":["Use column-wise assignment (df['col'] = ...) instead of cell-level mutations.","Treat Beam deferred frames as immutable; build new frames/expressions instead of in-place edits.","Reserve positional mutation for plain pandas pre/post processing."],"tags":["apache-beam","dataframe","order-sensitive","iloc","mutation"],"backgroundTag":"unsupported-operation","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}