{"record":{"id":"0d6684a6cbac201d","repo":"apache/beam","slug":"repeat-repeats-value-must-be-an-int-or-a-deferredseries","errorCode":null,"errorMessage":"repeat(repeats=) value must be an int or a DeferredSeries (encountered {type(repeats)}).","messagePattern":"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":2455,"sourceCode":"              'repeat', lambda series: series.repeat(repeats), [self._expr],\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.repeat(repeats_series),\n              [self._expr, repeats._expr],\n              requires_partition_by=partitionings.Index(),\n              preserves_partition_by=partitionings.Arbitrary()))\n    elif isinstance(repeats, list):\n      raise frame_base.WontImplementError(\n          \"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.\",\n          reason=\"order-sensitive\")\n    else:\n      raise TypeError(\n          \"repeat(repeats=) value must be an int or a \"\n          f\"DeferredSeries (encountered {type(repeats)}).\")\n\n  if hasattr(pd.Series, 'compare'):\n\n    @frame_base.with_docs_from(pd.Series)\n    @frame_base.args_to_kwargs(pd.Series)\n    @frame_base.populate_defaults(pd.Series)\n    def compare(self, other, align_axis, **kwargs):\n\n      if align_axis in ('index', 0):\n        preserves_partition = partitionings.Singleton()\n      elif align_axis in ('columns', 1):\n        preserves_partition = partitionings.Arbitrary()\n      else:\n        raise ValueError(\n            \"align_axis must be one of ('index', 0, 'columns', 1). \"\n            f\"got {align_axis!r}.\")","sourceCodeStart":2437,"sourceCodeEnd":2473,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/dataframe/frames.py#L2437-L2473","documentation":"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.","triggerScenarios":"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.","commonSituations":"Porting pandas code that repeats rows per-element lists into Beam DataFrames; accidentally passing a numpy array or float where an int is expected.","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)."],"exampleFix":"// before\ndf.repeat([1, 2, 3])\n// after\ncounts = beam.dataframe.from_pandas(pd.Series([1, 2, 3]), ...)  # as DeferredSeries\ndf.repeat(counts)\n// or, uniform repeat\ndf.repeat(3)","handlingStrategy":"type-guard","validationCode":"if not isinstance(repeats, (int, DeferredSeries)):\n    raise TypeError('repeats must be int or DeferredSeries')\nif isinstance(repeats, bool):\n    raise TypeError('bool is not a valid repeats value')","typeGuard":"def is_valid_repeats(repeats) -> bool:\n    return (isinstance(repeats, int) and not isinstance(repeats, bool)) or isinstance(repeats, DeferredSeries)","tryCatchPattern":"try:\n    out = s.repeat(repeats)\nexcept (TypeError, frame_base.WontImplementError):\n    out = s.repeat(int(repeats)) if np.isscalar(repeats) else None","preventionTips":["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."],"tags":["python","apache-beam","dataframe","type-mismatch"],"backgroundTag":"type-mismatch","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"}