apache/beam · error · TypeError
str.repeat(repeats=) value must be an int or a DeferredSerie
Error message
str.repeat(repeats=) value must be an int or a DeferredSeries (encountered {type(repeats)}). What it means
Beam DataFrames' str.repeat accepts only an int or a DeferredSeries for the repeats argument. When the argument is any other type (e.g. float, str, dict), the library raises TypeError immediately because there is no defined distributed semantics for it.
Source
Thrown at sdks/python/apache_beam/dataframe/frames.py:5089
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 "
"the type of the output column depends on the data. Please use "
"pd.CategoricalDtype with explicit categories.",
reason="non-deferred-columns")
split_cats = [View on GitHub (pinned to 12126d8942)
Solutions
- Cast the repeats value with int() before calling str.repeat.
- If repeats varies per row, convert the column to a DeferredSeries via beam.dataframe expressions or construct it as a column of the same DataFrame and pass it.
- Validate the type at the call site with isinstance(repeats, int) and raise a clear error early.
Example fix
// before df['col'].str.repeat(cfg['times']) # cfg['times'] is '3' // after df['col'].str.repeat(int(cfg['times']))
Defensive patterns
Strategy: type-guard
Validate before calling
if not isinstance(repeats, (int, pd.Series)):
raise TypeError(f'repeats must be int or DeferredSeries, got {type(repeats)}') Type guard
def is_valid_repeats(r):
return isinstance(r, (int, type(None))) or isinstance(r, pd.Series) Try / catch
try:
out = df['col'].str.repeat(repeats)
except TypeError as e:
out = df['col'].str.repeat(int(repeats)) Prevention
- Always cast repeat counts with int() at boundaries
- Never pass plain pandas Series where DeferredSeries is expected
- Validate config values parsed from strings/CLI before use
When it happens
Trigger: Calling s.str.repeat(2.0), s.str.repeat('3'), s.str.repeat([1,2]) that fell past the list branch, or passing a plain pandas Series instead of a DeferredSeries to str.repeat on a Beam DataFrame.
Common situations: Copy-pasting pandas code into Beam DataFrames; a config value or CLI argument parsed as string being passed straight to str.repeat; numpy integer scalars or floats from division used as repeat counts.
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
- repeat(repeats=) value must be an int or a DeferredSeries (e
- Passing a deferred series to round() is not supported, pleas
- 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/336482eab41466f9.
Report an issue: GitHub.