{"record":{"id":"6034f84f8f5157b1","repo":"apache/beam","slug":"unique-is-not-supported-by-default-because-it-produces-a-non","errorCode":null,"errorMessage":"unique() is not supported by default because it produces a non-deferred result: a numpy array. You can use the Beam-specific argument unique(as_series=True) to get the result as a DeferredSeries","messagePattern":"unique\\(\\) is not supported by default because it produces a non-deferred result: a numpy array\\. You can use the Beam-specific argument unique\\(as_series=True\\) to get the result as a DeferredSeries","errorType":"exception","errorClass":"WontImplementError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/dataframe/frames.py","lineNumber":2300,"sourceCode":"  round = frame_base._elementwise_method('round', base=pd.Series)\n\n  take = frame_base.wont_implement_method(\n      pd.Series, 'take', reason='deprecated')\n\n  to_dict = frame_base.wont_implement_method(\n      pd.Series, 'to_dict', reason=\"non-deferred-result\")\n\n  to_frame = frame_base._elementwise_method('to_frame', base=pd.Series)\n\n  @frame_base.with_docs_from(pd.Series)\n  def unique(self, as_series=False):\n    \"\"\"unique is not supported by default because it produces a\n    non-deferred result: an :class:`~numpy.ndarray`. You can use the\n    Beam-specific argument ``unique(as_series=True)`` to get the result as\n    a :class:`DeferredSeries`\"\"\"\n\n    if not as_series:\n      raise frame_base.WontImplementError(\n          \"unique() is not supported by default because it produces a \"\n          \"non-deferred result: a numpy array. You can use the Beam-specific \"\n          \"argument unique(as_series=True) to get the result as a \"\n          \"DeferredSeries\",\n          reason=\"non-deferred-result\")\n    return frame_base.DeferredFrame.wrap(\n        expressions.ComputedExpression(\n            'unique', lambda df: pd.Series(df.unique()), [self._expr],\n            preserves_partition_by=partitionings.Singleton(),\n            requires_partition_by=partitionings.Singleton(\n                reason=\"unique() cannot currently be parallelized.\")))\n\n  @frame_base.with_docs_from(pd.Series)\n  def update(self, other):\n    self._expr = expressions.ComputedExpression(\n        'update', lambda df, other: df.update(other) or df,\n        [self._expr, other._expr],\n        preserves_partition_by=partitionings.Arbitrary(),","sourceCodeStart":2282,"sourceCodeEnd":2318,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/dataframe/frames.py#L2282-L2318","documentation":"DeferredSeries.unique() in pandas returns a plain numpy array — a non-deferred, eagerly-materialized value — which the Beam dataframe API cannot produce. By default it raises WontImplementError (reason 'non-deferred-result'); a Beam-specific as_series=True option returns the distinct values as a DeferredSeries instead.","triggerScenarios":"Calling series.unique() without arguments (as_series defaults to False) on any DeferredSeries.","commonSituations":"Porting pandas code that does s.unique() for distinct values; using the result in set operations or len(); getting distinct categories for feature engineering.","solutions":["Call unique(as_series=True) and use the returned DeferredSeries","Use .drop_duplicates() on the series to keep a deferred pipeline","Convert to a distinct PCollection (e.g. via the Beam dataframe expression or a Distinct transform) if a PCollection is acceptable"],"exampleFix":"// before\nvalues = s.unique()\n// after\nvalues = s.unique(as_series=True)  # DeferredSeries","handlingStrategy":"validation","validationCode":"values = s.unique(as_series=True)  # never call s.unique() bare on a DeferredSeries","typeGuard":"from apache_beam.dataframe.frames import DeferredSeries\ndef is_deferred_series(x):\n    return isinstance(x, DeferredSeries)","tryCatchPattern":"from apache_beam.dataframe import frame_base\ntry:\n    values = s.unique(as_series=True)\nexcept frame_base.WontImplementError:\n    values = s.drop_duplicates()","preventionTips":["Search ported code for .unique() calls and add as_series=True","Prefer drop_duplicates() for deferred distinct values","Remember deferred APIs return frames/series, never numpy arrays"],"tags":["pandas","apache-beam","dataframe","non-deferred-result"],"backgroundTag":"unsupported-operation","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"}