{"record":{"id":"e7d0eb2519c0acee","repo":"apache/beam","slug":"accessing-an-item-by-an-integer-key-is-order-sensitive-for","errorCode":null,"errorMessage":"Accessing an item by an integer key is order sensitive for this Series.","messagePattern":"Accessing an item by an integer key is order sensitive for this Series\\.","errorType":"exception","errorClass":"WontImplementError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/dataframe/frames.py","lineNumber":1322,"sourceCode":"          expressions.ComputedExpression(\n              'combine_hasnans', lambda s: s.any(), [has_nans],\n              requires_partition_by=partitionings.Singleton(),\n              preserves_partition_by=partitionings.Singleton()))\n\n  @property  # type: ignore\n  @frame_base.with_docs_from(pd.Series)\n  def dtype(self):\n    return self._expr.proxy().dtype\n\n  dtypes = dtype\n\n  def __getitem__(self, key):\n    if _is_null_slice(key) or key is Ellipsis:\n      return self\n\n    elif (isinstance(key, int) or _is_integer_slice(key)\n          ) and self._expr.proxy().index._should_fallback_to_positional():\n      raise frame_base.WontImplementError(\n          \"Accessing an item by an integer key is order sensitive for this \"\n          \"Series.\",\n          reason=\"order-sensitive\")\n\n    elif isinstance(key, slice) or callable(key):\n      return frame_base.DeferredFrame.wrap(\n          expressions.ComputedExpression(\n              # yapf: disable\n              'getitem',\n              lambda df: df[key],\n              [self._expr],\n              requires_partition_by=partitionings.Arbitrary(),\n              preserves_partition_by=partitionings.Arbitrary()))\n\n    elif isinstance(key, DeferredSeries) and key._expr.proxy().dtype == bool:\n      return frame_base.DeferredFrame.wrap(\n          expressions.ComputedExpression(\n              # yapf: disable","sourceCodeStart":1304,"sourceCodeEnd":1340,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/dataframe/frames.py#L1304-L1340","documentation":"DeferredSeries.__getitem__ with an integer key (or integer slice) is rejected when the series' index type says it should NOT fall back to positional lookup. In that case an integer key would select by label, and the presence/absence of a label in distributed data makes the result order- and data-dependent, so Beam refuses it with reason \"order-sensitive\".","triggerScenarios":"s[3] or s[1:3] on a DeferredSeries whose index._should_fallback_to_positional() is False (e.g. non-default integer index); typically with an integer-labeled index.","commonSituations":"Using pandas positional-indexing habits on a deferred series with an integer index; slicing the first N elements assuming row order.","solutions":["Look up by explicit label instead of a bare integer if the index is label-based.","Use a non-integer slice or a label-based key, or restructure with .loc-style semantics via supported deferred operations.","Convert to pandas (to_pandas()) for positional integer indexing."],"exampleFix":"// before\ns[0]  # integer key on non-positional deferred index\n// after\ns[s.index[0]]  # or work on s.to_pandas() for positional access","handlingStrategy":"validation","validationCode":"if (isinstance(key, int) or (isinstance(key, slice) and all(\n        v is None or isinstance(v, int) for v in (key.start, key.stop, key.step)))) \\\n        and not s._expr.proxy().index._should_fallback_to_positional():\n    raise ValueError(\"integer key/slice is order-sensitive here; use labels or to_pandas()\")","typeGuard":"def is_positional_safe(series, key):\n    return not (isinstance(key, int) or _is_integer_slice(key)) or series._expr.proxy().index._should_fallback_to_positional()","tryCatchPattern":"from apache_beam.dataframe import frame_base\ntry:\n    val = s[int_key]\nexcept frame_base.WontImplementError:\n    val = s.to_pandas()[int_key]  # or use label-based lookup","preventionTips":["Know whether your deferred index is label-based or positional before integer indexing.","Avoid integer slices like s[1:3] on deferred series with integer labels.","Use label-based keys or supported deferred expressions for selection."],"tags":["apache-beam","dataframe","pandas","indexing"],"backgroundTag":"order-sensitive-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"}