{"record":{"id":"a6f0295dbcbffd16","repo":"apache/beam","slug":"str-repeat-repeats-repeats-must-be-an-int-or-a","errorCode":null,"errorMessage":"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.","messagePattern":"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\\.","errorType":"exception","errorClass":"WontImplementError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/dataframe/frames.py","lineNumber":5084,"sourceCode":"              # pandas to compute this proxy. Currently it incorrectly infers\n              # dtype bool, may require upstream fix.\n              proxy=self._expr.proxy(),\n              requires_partition_by=partitionings.Arbitrary(),\n              preserves_partition_by=partitionings.Arbitrary()))\n    elif isinstance(repeats, frame_base.DeferredBase):\n      return frame_base.DeferredFrame.wrap(\n          expressions.ComputedExpression(\n              'repeat',\n              lambda series, repeats_series: series.str.repeat(repeats_series),\n              [self._expr, repeats._expr],\n              # TODO(https://github.com/apache/beam/issues/20573): Defer to\n              # pandas to compute this proxy. Currently it incorrectly infers\n              # dtype bool, may require upstream fix.\n              proxy=self._expr.proxy(),\n              requires_partition_by=partitionings.Index(),\n              preserves_partition_by=partitionings.Arbitrary()))\n    elif isinstance(repeats, list):\n      raise frame_base.WontImplementError(\n          \"str.repeat(repeats=) repeats must be an int or a DeferredSeries. \"\n          \"Lists are not supported because they make this operation sensitive \"\n          \"to the order of the data.\", reason=\"order-sensitive\")\n    else:\n      raise TypeError(\"str.repeat(repeats=) value must be an int or a \"\n                      f\"DeferredSeries (encountered {type(repeats)}).\")\n\n  @frame_base.with_docs_from(pd.Series.str)\n  @frame_base.args_to_kwargs(pd.Series.str)\n  def get_dummies(self, **kwargs):\n    \"\"\"\n    Series must be categorical dtype. Please cast to ``CategoricalDtype``\n    to ensure correct categories.\n    \"\"\"\n    dtype = self._expr.proxy().dtype\n    if not isinstance(dtype, pd.CategoricalDtype):\n      raise frame_base.WontImplementError(\n          \"get_dummies() of non-categorical type is not supported because \"","sourceCodeStart":5066,"sourceCodeEnd":5102,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/dataframe/frames.py#L5066-L5102","documentation":"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).","triggerScenarios":"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.","commonSituations":"Porting pandas str.repeat examples that use list counts; generating per-row padded strings with varying lengths; mixing plain lists with deferred pipelines.","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."],"exampleFix":"// before\nresult = s.str.repeat([1, 2, 3])\n\n// after\ncounts = make_deferred_series([1, 2, 3], index=s.index)  # aligned deferred series\nresult = s.str.repeat(counts)","handlingStrategy":"type-guard","validationCode":"if isinstance(repeats, list):\n    raise ValueError(\"str.repeat list counts unsupported in Beam; use int or DeferredSeries\")","typeGuard":"def valid_repeat_arg(repeats):\n    return isinstance(repeats, int) and not isinstance(repeats, bool) or isinstance(repeats, frame_base.DeferredFrame)","tryCatchPattern":"try:\n    out = s.str.repeat(repeats)\nexcept apachebeam.WontImplementError:\n    out = s.str.repeat(int(np.mean(repeats)))  # or build a DeferredSeries","preventionTips":["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."],"tags":["apache-beam","dataframe","order-sensitive","string-methods","pandas"],"backgroundTag":"invalid-argument-value","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}