{"record":{"id":"b38d135cbdd5a14b","repo":"apache/beam","slug":"replace-method-method-r-is-not-supported-because-it-is-order","errorCode":null,"errorMessage":"replace(method={method!r}) is not supported because it is order sensitive. Only replace(method=None) is supported.","messagePattern":"replace\\(method=(.+?)\\) is not supported because it is order sensitive\\. Only replace\\(method=None\\) is supported\\.","errorType":"exception","errorClass":"WontImplementError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/dataframe/frames.py","lineNumber":684,"sourceCode":"\n  @frame_base.with_docs_from(pd.DataFrame)\n  @frame_base.args_to_kwargs(pd.DataFrame)\n  @frame_base.populate_defaults(pd.DataFrame)\n  @frame_base.maybe_inplace\n  def replace(self, to_replace, value, limit, method, **kwargs):\n    \"\"\"``method`` is not supported in the Beam DataFrame API because it is\n    order-sensitive. It cannot be specified.\n\n    If ``limit`` is specified this operation is not parallelizable.\"\"\"\n    # pylint: disable-next=c-extension-no-member\n    value_compare = None if PD_VERSION < (1, 4) else lib.no_default\n    if method is not None and not isinstance(to_replace,\n                                             dict) and value is value_compare:\n      # pandas only relies on method if to_replace is not a dictionary, and\n      # value is the <no_default> value. This is different than\n      # if ``None`` is explicitly passed for ``value``. In this case, it will be\n      # respected\n      raise frame_base.WontImplementError(\n          f\"replace(method={method!r}) is not supported because it is \"\n          \"order sensitive. Only replace(method=None) is supported.\",\n          reason=\"order-sensitive\")\n\n    if limit is None:\n      requires_partition_by = partitionings.Arbitrary()\n    else:\n      requires_partition_by = partitionings.Singleton(\n          reason=(\n              f\"replace(limit={limit!r}) cannot currently be parallelized. It \"\n              \"requires collecting all data on a single node.\"))\n    return frame_base.DeferredFrame.wrap(\n        expressions.ComputedExpression(\n            'replace', lambda df: df.replace(\n                to_replace=to_replace, value=value, limit=limit, method=method,\n                **kwargs), [self._expr],\n            preserves_partition_by=partitionings.Arbitrary(),\n            requires_partition_by=requires_partition_by))","sourceCodeStart":666,"sourceCodeEnd":702,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/dataframe/frames.py#L666-L702","documentation":"replace(method='pad'/'nearest'/...) interpolates replacements based on data order, which Beam cannot guarantee. It is only raised when to_replace is NOT a dict and value is left at its default, because pandas only honors method in that case. Passing method=None (or to_replace as a dict, or an explicit value) is supported.","triggerScenarios":"series.replace([1,2], method='pad') — i.e. replace with a scalar/list to_replace, no explicit value, and a non-None method — on a deferred frame.","commonSituations":"Porting pandas forward-fill-style replace calls; legacy pandas code using replace(method='pad') (deprecated in pandas 2.x anyway); cleaning pipelines that interpolate missing sentinels.","solutions":["Pass an explicit value: series.replace(to_replace, value=<replacement>).","Pass to_replace as a dict mapping old->new values, which makes method irrelevant.","Set method=None and supply a value.","Use fillna with an explicit value for sentinel replacement."],"exampleFix":"// before\ns = s.replace(-1, method='pad')\n// after\ns = s.replace(-1, value=None)  # or s.replace({-1: 0})","handlingStrategy":"validation","validationCode":"if method is not None and not isinstance(to_replace, dict) and value is pd.api.types.pandas_dtype.__class__ if False else (method is not None and not isinstance(to_replace, dict)):\n    raise ValueError('Pass value= explicitly or use a dict for to_replace')","typeGuard":"def replace_is_deferrable(to_replace, value, method=None) -> bool:\n    return method is None or isinstance(to_replace, dict) or value is not None","tryCatchPattern":"try:\n    s = s.replace(-1, method='pad')\nexcept frame_base.WontImplementError:\n    s = s.replace({-1: 0})","preventionTips":["Always pass an explicit value= to replace in Beam","Use dict-form to_replace so method is irrelevant","Note replace(method=...) is deprecated in pandas 2.x anyway — avoid it everywhere"],"tags":["apache-beam","dataframe","pandas","replace","order-sensitive"],"backgroundTag":"unsupported-operation","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T21:17:11.552Z"}