{"record":{"id":"7e95aae7c896ea09","repo":"apache/beam","slug":"repeat-repeats-repeats-must-be-an-int-or-a-deferredseries","errorCode":null,"errorMessage":"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":"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":2449,"sourceCode":"  def repeat(self, repeats, axis):\n    \"\"\"``repeats`` must be an ``int`` or a :class:`DeferredSeries`. Lists are\n    not supported because they make this operation order-sensitive.\"\"\"\n    if isinstance(repeats, int):\n      return frame_base.DeferredFrame.wrap(\n          expressions.ComputedExpression(\n              '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()","sourceCodeStart":2431,"sourceCodeEnd":2467,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/dataframe/frames.py#L2431-L2467","documentation":"DeferredSeries.repeat() with repeats as a plain Python list would map each element to its repeat count positionally, making the result depend on row order, which Beam cannot guarantee. Only an int (same count for all) or a DeferredSeries (join by index) is accepted; a list raises WontImplementError (reason 'order-sensitive'), and other types raise TypeError.","triggerScenarios":"Calling series.repeat([1, 2, 3]) or passing any list/numpy array of per-element counts as repeats.","commonSituations":"Porting pandas s.repeat([2,2,3]) patterns; replicating rows with per-row multiplicities loaded as a list; synthetic data expansion in pipelines.","solutions":["Pass a single int if every element should repeat the same number of times: series.repeat(2)","Build a DeferredSeries of repeat counts with the same index as the source and pass that","If counts are fixed per position and data is small, materialize with pandas instead of the deferred API"],"exampleFix":"// before\ns.repeat([2, 3, 1])\n// after\ns.repeat(repeats_series)  # DeferredSeries with matching index","handlingStrategy":"type-guard","validationCode":"assert repeats is None or isinstance(repeats, (int, DeferredSeries)), 'repeat: use int or DeferredSeries'","typeGuard":"from apache_beam.dataframe.frames import DeferredSeries\ndef is_beam_safe_repeats(repeats):\n    return isinstance(repeats, (int, DeferredSeries)) and not isinstance(repeats, bool)","tryCatchPattern":"from apache_beam.dataframe import frame_base\ntry:\n    out = s.repeat(2)\nexcept (frame_base.WontImplementError, TypeError):\n    out = s.repeat(repeats_deferred_series)","preventionTips":["Convert per-row repeat lists into a DeferredSeries with a matching index","Use a scalar int when all rows repeat equally","Avoid positional list arguments in any deferred-frame API"],"tags":["pandas","apache-beam","dataframe","order-sensitive"],"backgroundTag":"incompatible-source-type","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"}