{"record":{"id":"2bb3b2545a2037cc","repo":"apache/beam","slug":"accessing-a-deferredseries-with-an-iterator-is-sensitive-to","errorCode":null,"errorMessage":"Accessing a DeferredSeries with an iterator is sensitive to the order of the data.","messagePattern":"Accessing a DeferredSeries with an iterator is sensitive to the order of the data\\.","errorType":"exception","errorClass":"WontImplementError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/dataframe/frames.py","lineNumber":1348,"sourceCode":"              # yapf: disable\n              'getitem',\n              lambda df: df[key],\n              [self._expr],\n              requires_partition_by=partitionings.Arbitrary(),\n              preserves_partition_by=partitionings.Arbitrary()))\n\n    elif isinstance(key, DeferredSeries) and key._expr.proxy().dtype == bool:\n      return frame_base.DeferredFrame.wrap(\n          expressions.ComputedExpression(\n              # yapf: disable\n              'getitem',\n              lambda df, indexer: df[indexer],\n              [self._expr, key._expr],\n              requires_partition_by=partitionings.Index(),\n              preserves_partition_by=partitionings.Arbitrary()))\n\n    elif pd.core.series.is_iterator(key) or pd.core.common.is_bool_indexer(key):\n      raise frame_base.WontImplementError(\n          \"Accessing a DeferredSeries with an iterator is sensitive to the \"\n          \"order of the data.\",\n          reason=\"order-sensitive\")\n\n    else:\n      # We could consider returning a deferred scalar, but that might\n      # be more surprising than a clear error.\n      raise frame_base.WontImplementError(\n          f\"Indexing a series with key of type {type(key)} is not supported \"\n          \"because it produces a non-deferred result.\",\n          reason=\"non-deferred-result\")\n\n  @frame_base.with_docs_from(pd.Series)\n  def keys(self):\n    return self.index\n\n  # Series.T == transpose. Both are a no-op\n  T = frame_base._elementwise_method('T', base=pd.Series)","sourceCodeStart":1330,"sourceCodeEnd":1366,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/dataframe/frames.py#L1330-L1366","documentation":"Indexing a DeferredSeries with an iterator key or a boolean indexer (a list/array of booleans) is rejected because a boolean mask's elements are paired with rows positionally, and positions are not meaningful in Beam's arbitrarily partitioned data. Beam raises WontImplementError with reason \"order-sensitive\".","triggerScenarios":"s[iter([True, False, ...])] or s[[True, False, True]] (list/ndarray of booleans accepted by pd.core.common.is_bool_indexer) on a DeferredSeries.","commonSituations":"Porting pandas mask-filtering code; building a boolean list from another column and using it directly as an indexer.","solutions":["Filter with a boolean DeferredSeries instead: s[s > 0] or s[mask_series] where mask_series is itself deferred.","Use supported filtering APIs (e.g. s.loc with a deferred boolean expression).","If the mask is small/static, apply the filter after to_pandas()."],"exampleFix":"// before\nmask = [True, False, True]\ns[mask]  # WontImplementError\n// after\ns = s[s > 0]  # deferred boolean expression","handlingStrategy":"validation","validationCode":"import pandas as pd\nif pd.core.series.is_iterator(key) or pd.core.common.is_bool_indexer(key):\n    raise ValueError(\"pass a deferred boolean Series instead of a list/iterator mask\")","typeGuard":"def is_deferred_mask(series, key):\n    return isinstance(key, DeferredSeries)","tryCatchPattern":"from apache_beam.dataframe import frame_base\ntry:\n    out = s[bool_list]\nexcept frame_base.WontImplementError:\n    out = s[s > threshold]  # build the mask inside the deferred graph","preventionTips":["Never index deferred frames with Python lists/iterators of booleans.","Express masks as DeferredSeries expressions (s > x, s.isin(...)).","Keep mask and data in the same (deferred) world."],"tags":["apache-beam","dataframe","pandas","indexing","order-sensitivity"],"backgroundTag":"order-sensitive-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"}