apache/beam · error · TypeError
repeat(repeats=) value must be an int or a DeferredSeries (e
Error message
repeat(repeats=) value must be an int or a DeferredSeries (encountered {type(repeats)}). What it means
DeferredSeries.repeat only supports an integer repeat count or a DeferredSeries of counts. Python lists (or other iterables) are rejected: a per-element list of counts makes the operation order-sensitive, which Beam's distributed model cannot guarantee. Lists trigger a WontImplementError (order-sensitive) while any other non-int, non-DeferredSeries type triggers this TypeError.
Source
Thrown at sdks/python/apache_beam/dataframe/frames.py:2455
'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()
elif align_axis in ('columns', 1):
preserves_partition = partitionings.Arbitrary()
else:
raise ValueError(
"align_axis must be one of ('index', 0, 'columns', 1). "
f"got {align_axis!r}.")View on GitHub (pinned to 12126d8942)
Solutions
- Pass a plain Python int if all elements repeat the same number of times: s.repeat(3).
- Convert the counts into a DeferredSeries aligned with s, e.g. s.repeat(expressions.../ s2) where s2 is a DeferredSeries, instead of a list.
- Cast the value to int if it is a numeric type like numpy.int64 or float with integral value.
- Do the repeat before building the Beam DataFrame (on plain pandas) or with a different Beam transform (FlatMap).
Example fix
// before df.repeat([1, 2, 3]) // after counts = beam.dataframe.from_pandas(pd.Series([1, 2, 3]), ...) # as DeferredSeries df.repeat(counts) // or, uniform repeat df.repeat(3)
Defensive patterns
Strategy: type-guard
Validate before calling
if not isinstance(repeats, (int, DeferredSeries)):
raise TypeError('repeats must be int or DeferredSeries')
if isinstance(repeats, bool):
raise TypeError('bool is not a valid repeats value') Type guard
def is_valid_repeats(repeats) -> bool:
return (isinstance(repeats, int) and not isinstance(repeats, bool)) or isinstance(repeats, DeferredSeries) Try / catch
try:
out = s.repeat(repeats)
except (TypeError, frame_base.WontImplementError):
out = s.repeat(int(repeats)) if np.isscalar(repeats) else None Prevention
- Use a scalar int for uniform repeats.
- Convert count lists to a DeferredSeries before calling repeat.
- Cast numpy integer types to int.
- Remember lists are banned because they are order-sensitive in Beam.
When it happens
Trigger: Calling series.repeat([...]) with a list of counts; calling series.repeat('3') or series.repeat(3.0) with a non-int scalar; passing a plain pandas Series instead of a DeferredSeries.
Common situations: Porting pandas code that repeats rows per-element lists into Beam DataFrames; accidentally passing a numpy array or float where an int is expected.
Understand the failure class
Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.
Related errors
- Passing a deferred series to round() is not supported, pleas
- str.repeat(repeats=) value must be an int or a DeferredSerie
- Cannot specify both 'labels' and 'index'/'columns'
- axis must be one of (0, 1, 'index', 'columns'), got '%s'
- groupby(as_index=False)
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/0d6684a6cbac201d.
Report an issue: GitHub.