apache/beam · error · WontImplementError
repeat(repeats=) repeats must be an int or a…
Error message
repeat(repeats=) repeats must be an int or a DeferredSeries. Lists are not supported because they make this operation sensitive to the order of the data.
What it means
DeferredSeries.repeat() with repeats as a plain Python list would map each element to its repeat count positionally, making the result depend on row order, which Beam cannot guarantee. Only an int (same count for all) or a DeferredSeries (join by index) is accepted; a list raises WontImplementError (reason 'order-sensitive'), and other types raise TypeError.
Solutions
- Pass a single int if every element should repeat the same number of times: series.repeat(2)
- Build a DeferredSeries of repeat counts with the same index as the source and pass that
- If counts are fixed per position and data is small, materialize with pandas instead of the deferred API
Example fix
// before s.repeat([2, 3, 1]) // after s.repeat(repeats_series) # DeferredSeries with matching index
Defensive patterns
Strategy: type-guard
Validate before calling
assert repeats is None or isinstance(repeats, (int, DeferredSeries)), 'repeat: use int or DeferredSeries'
Type guard
from apache_beam.dataframe.frames import DeferredSeries
def is_beam_safe_repeats(repeats):
return isinstance(repeats, (int, DeferredSeries)) and not isinstance(repeats, bool) Try / catch
from apache_beam.dataframe import frame_base
try:
out = s.repeat(2)
except (frame_base.WontImplementError, TypeError):
out = s.repeat(repeats_deferred_series) Prevention
- Convert per-row repeat lists into a DeferredSeries with a matching index
- Use a scalar int when all rows repeat equally
- Avoid positional list arguments in any deferred-frame API
When it happens
Trigger: Calling series.repeat([1, 2, 3]) or passing any list/numpy array of per-element counts as repeats.
Common situations: Porting pandas s.repeat([2,2,3]) patterns; replicating rows with per-row multiplicities loaded as a list; synthetic data expansion in pipelines.
Understand the failure class
Background: "is not a compatible type" / "cannot merge" errors: when a value's type doesn't match what the library requires — this error's family across 65 libraries.
Related errors
- align(method= ) is not supported because it is order…
- axis must be 'index' when upper and/or lower are a…
- drop_duplicates(ignore_index=False) is not supported…
- drop_duplicates(keep= ) is not supported because it is…
- duplicated(keep= ) is not supported because it is sensitive…
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/7e95aae7c896ea09.
Report an issue: GitHub.
Appendix: source
Thrown at sdks/python/apache_beam/dataframe/frames.py:2449
def repeat(self, repeats, axis):
"""``repeats`` must be an ``int`` or a :class:`DeferredSeries`. Lists are
not supported because they make this operation order-sensitive."""
if isinstance(repeats, int):
return frame_base.DeferredFrame.wrap(
expressions.ComputedExpression(
'repeat', lambda series: series.repeat(repeats), [self._expr],
requires_partition_by=partitionings.Arbitrary(),
preserves_partition_by=partitionings.Arbitrary()))
elif isinstance(repeats, frame_base.DeferredBase):
return frame_base.DeferredFrame.wrap(
expressions.ComputedExpression(
'repeat',
lambda series, repeats_series: series.repeat(repeats_series),
[self._expr, repeats._expr],
requires_partition_by=partitionings.Index(),
preserves_partition_by=partitionings.Arbitrary()))
elif isinstance(repeats, list):
raise frame_base.WontImplementError(
"repeat(repeats=) repeats must be an int or a DeferredSeries. "
"Lists are not supported because they make this operation sensitive "
"to the order of the data.",
reason="order-sensitive")
else:
raise TypeError(
"repeat(repeats=) value must be an int or a "
f"DeferredSeries (encountered {type(repeats)}).")
if hasattr(pd.Series, 'compare'):
@frame_base.with_docs_from(pd.Series)
@frame_base.args_to_kwargs(pd.Series)
@frame_base.populate_defaults(pd.Series)
def compare(self, other, align_axis, **kwargs):
if align_axis in ('index', 0):
preserves_partition = partitionings.Singleton()View on GitHub (pinned to 12126d8942)