apache/beam · error · WontImplementError
str.repeat(repeats=) repeats must be an int or a…
Error message
str.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
DeferredStringMethods.str.repeat raises WontImplementError when `repeats` is a Python list. A per-element repeats list must line up positionally with the series rows, which depends on row order, so Beam only accepts an int (same repeat count for all) or a DeferredSeries (aligned by index).
Solutions
- Use a scalar int if all rows repeat the same number of times: s.str.repeat(3).
- Convert the counts into a deferred Beam Series (aligned on the same index) and pass that as `repeats`.
- Compute repetition with an expression using .str * counts on Series pairs if a Series of counts exists.
- Fall back to plain pandas for this step outside the Beam pipeline.
Example fix
// before result = s.str.repeat([1, 2, 3]) // after counts = make_deferred_series([1, 2, 3], index=s.index) # aligned deferred series result = s.str.repeat(counts)
Defensive patterns
Strategy: type-guard
Validate before calling
if isinstance(repeats, list):
raise ValueError("str.repeat list counts unsupported in Beam; use int or DeferredSeries") Type guard
def valid_repeat_arg(repeats):
return isinstance(repeats, int) and not isinstance(repeats, bool) or isinstance(repeats, frame_base.DeferredFrame) Try / catch
try:
out = s.str.repeat(repeats)
except apachebeam.WontImplementError:
out = s.str.repeat(int(np.mean(repeats))) # or build a DeferredSeries Prevention
- Use a scalar int when the repeat count is uniform.
- Materialize per-row counts as a deferred Series aligned on the same index.
- Avoid list arguments in any Beam dataframe string API.
When it happens
Trigger: s.str.repeat([1, 2, 3]) or any list of per-row repeat counts on a deferred Beam Series; also note the parallel TypeError branch for any other non-int, non-Series value.
Common situations: Porting pandas str.repeat examples that use list counts; generating per-row padded strings with varying lengths; mixing plain lists with deferred pipelines.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- others must be None, DeferredSeries, or list[DeferredSeries]
- 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…
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/a6f0295dbcbffd16.
Report an issue: GitHub.
Appendix: source
Thrown at sdks/python/apache_beam/dataframe/frames.py:5084
# pandas to compute this proxy. Currently it incorrectly infers
# dtype bool, may require upstream fix.
proxy=self._expr.proxy(),
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.str.repeat(repeats_series),
[self._expr, repeats._expr],
# TODO(https://github.com/apache/beam/issues/20573): Defer to
# pandas to compute this proxy. Currently it incorrectly infers
# dtype bool, may require upstream fix.
proxy=self._expr.proxy(),
requires_partition_by=partitionings.Index(),
preserves_partition_by=partitionings.Arbitrary()))
elif isinstance(repeats, list):
raise frame_base.WontImplementError(
"str.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("str.repeat(repeats=) value must be an int or a "
f"DeferredSeries (encountered {type(repeats)}).")
@frame_base.with_docs_from(pd.Series.str)
@frame_base.args_to_kwargs(pd.Series.str)
def get_dummies(self, **kwargs):
"""
Series must be categorical dtype. Please cast to ``CategoricalDtype``
to ensure correct categories.
"""
dtype = self._expr.proxy().dtype
if not isinstance(dtype, pd.CategoricalDtype):
raise frame_base.WontImplementError(
"get_dummies() of non-categorical type is not supported because "View on GitHub (pinned to 12126d8942)