apache/beam · error · WontImplementError

Accessing an item by an integer key is order sensitive for…

Error message

Accessing an item by an integer key is order sensitive for this Series.

What it means

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".

Solutions

  1. Look up by explicit label instead of a bare integer if the index is label-based.
  2. Use a non-integer slice or a label-based key, or restructure with .loc-style semantics via supported deferred operations.
  3. Convert to pandas (to_pandas()) for positional integer indexing.

Example fix

// before
s[0]  # integer key on non-positional deferred index
// after
s[s.index[0]]  # or work on s.to_pandas() for positional access
Defensive patterns

Strategy: validation

Validate before calling

if (isinstance(key, int) or (isinstance(key, slice) and all(
        v is None or isinstance(v, int) for v in (key.start, key.stop, key.step)))) \
        and not s._expr.proxy().index._should_fallback_to_positional():
    raise ValueError("integer key/slice is order-sensitive here; use labels or to_pandas()")

Type guard

def is_positional_safe(series, key):
    return not (isinstance(key, int) or _is_integer_slice(key)) or series._expr.proxy().index._should_fallback_to_positional()

Try / catch

from apache_beam.dataframe import frame_base
try:
    val = s[int_key]
except frame_base.WontImplementError:
    val = s.to_pandas()[int_key]  # or use label-based lookup

Prevention

When it happens

Trigger: 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.

Common situations: Using pandas positional-indexing habits on a deferred series with an integer index; slicing the first N elements assuming row order.

Related errors


AI-assisted analysis of apache/beam@12126d8942 (2026-09-13). Data as JSON: /api/errors/e7d0eb2519c0acee. Report an issue: GitHub.

Appendix: source

Thrown at sdks/python/apache_beam/dataframe/frames.py:1322

          expressions.ComputedExpression(
              'combine_hasnans', lambda s: s.any(), [has_nans],
              requires_partition_by=partitionings.Singleton(),
              preserves_partition_by=partitionings.Singleton()))

  @property  # type: ignore
  @frame_base.with_docs_from(pd.Series)
  def dtype(self):
    return self._expr.proxy().dtype

  dtypes = dtype

  def __getitem__(self, key):
    if _is_null_slice(key) or key is Ellipsis:
      return self

    elif (isinstance(key, int) or _is_integer_slice(key)
          ) and self._expr.proxy().index._should_fallback_to_positional():
      raise frame_base.WontImplementError(
          "Accessing an item by an integer key is order sensitive for this "
          "Series.",
          reason="order-sensitive")

    elif isinstance(key, slice) or callable(key):
      return frame_base.DeferredFrame.wrap(
          expressions.ComputedExpression(
              # yapf: disable
              'getitem',
              lambda df: df[key],
              [self._expr],
              requires_partition_by=partitionings.Arbitrary(),
              preserves_partition_by=partitionings.Arbitrary()))

    elif isinstance(key, DeferredSeries) and key._expr.proxy().dtype == bool:
      return frame_base.DeferredFrame.wrap(
          expressions.ComputedExpression(
              # yapf: disable

View on GitHub (pinned to 12126d8942)