{"record":{"id":"336482eab41466f9","repo":"apache/beam","slug":"str-repeat-repeats-value-must-be-an-int-or-a-deferredseries","errorCode":null,"errorMessage":"str.repeat(repeats=) value must be an int or a DeferredSeries (encountered {type(repeats)}).","messagePattern":"str\\.repeat\\(repeats=\\) value must be an int or a DeferredSeries \\(encountered (.+?)\\)\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/dataframe/frames.py","lineNumber":5089,"sourceCode":"    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 \"\n          \"the type of the output column depends on the data. Please use \"\n          \"pd.CategoricalDtype with explicit categories.\",\n          reason=\"non-deferred-columns\")\n\n    split_cats = [","sourceCodeStart":5071,"sourceCodeEnd":5107,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/dataframe/frames.py#L5071-L5107","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\ndf['col'].str.repeat(cfg['times'])  # cfg['times'] is '3'\n// after\ndf['col'].str.repeat(int(cfg['times']))","handlingStrategy":"type-guard","validationCode":"if not isinstance(repeats, (int, pd.Series)):\n    raise TypeError(f'repeats must be int or DeferredSeries, got {type(repeats)}')","typeGuard":"def is_valid_repeats(r):\n    return isinstance(r, (int, type(None))) or isinstance(r, pd.Series)","tryCatchPattern":"try:\n    out = df['col'].str.repeat(repeats)\nexcept TypeError as e:\n    out = df['col'].str.repeat(int(repeats))","preventionTips":["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"],"tags":["python","apache-beam","dataframe","type-mismatch"],"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-14T16:17:12.679Z"}