apache/beam · error · WontImplementError
Integer slices are not supported as they are ambiguous…
Error message
Integer slices are not supported as they are ambiguous. Please use iloc or loc with integer slices.
What it means
Slicing a DeferredFrame with an integer slice like df[1:3] (or a list key with integer slice) is ambiguous: whether it means positional or label-based slicing depends on the actual contents of the index, which the deferred expression layer cannot determine. The library raises WontImplementError telling you to use iloc or loc explicitly.
Solutions
- Use df.iloc[0:100] for positional slicing or df.loc[0:100] for label-based slicing, matching your intent
- Skip/truncate rows at the PCollection level (e.g. a limit transform) if you just want the first N rows
- Use head() where supported instead of integer slicing
Example fix
// before df[0:100] // after df.iloc[0:100] # positional, or df.loc[0:100] for label-based
Defensive patterns
Strategy: validation
Validate before calling
assert not isinstance(key, slice) or not (key.start is not None or key.stop is not None) or not all(isinstance(v, int) for v in (key.start, key.stop) if v is not None), 'use .iloc/.loc for integer slices'
Type guard
def is_ambiguous_slice(key):
return isinstance(key, slice) and any(
isinstance(v, int) for v in (key.start, key.stop) if v is not None) Try / catch
from apache_beam.dataframe import frame_base
try:
out = df.iloc[0:100]
except frame_base.WontImplementError:
out = df.iloc[0:100] # df[0:100] would raise; always use iloc/loc Prevention
- Replace df[a:b] with df.iloc[a:b] (positional) or df.loc[a:b] (labels) in Beam code
- Never rely on RangeIndex defaults to disambiguate slicing
- Keep head()/tail() idioms instead of integer slicing for row limits
When it happens
Trigger: Using df[slice(start, stop)] where start/stop are ints (detected by _is_integer_slice), e.g. df[0:5], df[10:], on a DeferredDataFrame/Series __getitem__; null slices (df[:]) are fine and return self.
Common situations: Porting pandas df[0:100] head-slicing idioms; truncating data in notebooks; code written for default integer RangeIndex assumed.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- Accessing a DeferredSeries with an iterator is sensitive to…
- Accessing an item by an integer key is order sensitive for…
- align(copy=False) is not supported because it might be an…
- align(method= ) is not supported because it is order…
- append(ignore_index=True) is order sensitive because it…
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/faec3e61c63ace7a.
Report an issue: GitHub.
Appendix: source
Thrown at sdks/python/apache_beam/dataframe/frames.py:2539
def __getitem__(self, key):
# TODO: Replicate pd.DataFrame.__getitem__ logic
if isinstance(key, DeferredSeries) and key._expr.proxy().dtype == bool:
return self.loc[key]
elif isinstance(key, frame_base.DeferredBase):
# Fail early if key is a DeferredBase as it interacts surprisingly with
# key in self._expr.proxy().columns
raise NotImplementedError(
"Indexing with a non-bool deferred frame is not yet supported. "
"Consider using df.loc[...]")
elif isinstance(key, slice):
if _is_null_slice(key):
return self
elif _is_integer_slice(key):
# This depends on the contents of the index.
raise frame_base.WontImplementError(
"Integer slices are not supported as they are ambiguous. Please "
"use iloc or loc with integer slices.")
else:
return self.loc[key]
elif (
(isinstance(key, list) and all(key_column in self._expr.proxy().columns
for key_column in key)) or
key in self._expr.proxy().columns):
return self._elementwise(lambda df: df[key], 'get_column')
else:
raise NotImplementedError(key)
def __contains__(self, key):
# Checks if proxy has the given column
return self._expr.proxy().__contains__(key)
View on GitHub (pinned to 12126d8942)