{"record":{"id":"1f979c8876210780","repo":"apache/beam","slug":"axis-must-be-index-when-upper-and-or-lower-are-a","errorCode":null,"errorMessage":"axis must be 'index' when upper and/or lower are a DeferredFrame","messagePattern":"axis must be 'index' when upper and/or lower are a DeferredFrame","errorType":"exception","errorClass":"WontImplementError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/dataframe/frames.py","lineNumber":3012,"sourceCode":"\n  memory_usage = frame_base.wont_implement_method(\n      pd.DataFrame, 'memory_usage', reason=\"non-deferred-result\")\n  info = frame_base.wont_implement_method(\n      pd.DataFrame, 'info', reason=\"non-deferred-result\")\n\n\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 clip(self, axis, **kwargs):\n    \"\"\"``lower`` and ``upper`` must be :class:`DeferredSeries` instances, or\n    constants.  Array-like arguments are not supported because they are\n    order-sensitive.\"\"\"\n\n    if any(isinstance(kwargs.get(arg, None), frame_base.DeferredFrame)\n           for arg in ('upper', 'lower')) and axis not in (0, 'index'):\n      raise frame_base.WontImplementError(\n          \"axis must be 'index' when upper and/or lower are a DeferredFrame\",\n          reason='order-sensitive')\n\n    return frame_base._elementwise_method('clip', base=pd.DataFrame)(self,\n                                                                     axis=axis,\n                                                                     **kwargs)\n\n  @frame_base.with_docs_from(pd.DataFrame)\n  @frame_base.args_to_kwargs(pd.DataFrame)\n  @frame_base.populate_defaults(pd.DataFrame)\n  def corr(self, method, min_periods):\n    \"\"\"Only ``method=\"pearson\"`` can be parallelized. Other methods require\n    collecting all data on a single worker (see\n    https://s.apache.org/dataframe-non-parallel-operations for details).\n    \"\"\"\n    if method == 'pearson':\n      proxy = self._expr.proxy().corr()\n      columns = list(proxy.columns)","sourceCodeStart":2994,"sourceCodeEnd":3030,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/dataframe/frames.py#L2994-L3030","documentation":"DeferredSeries/DataFrame.clip supports DeferredFrame bounds (lower/upper as deferred series) only when axis='index' (axis 0), because aligning bound arrays along columns would be order-sensitive. Passing axis=1/'columns' with a DeferredFrame bound raises WontImplementError.","triggerScenarios":"Calling `ddf.clip(lower=some_deferred_series, axis=1)` or `axis='columns'` where lower and/or upper is a DeferredFrame/DeferredSeries.","commonSituations":"Clipping each row/column against a series of thresholds computed in the same pipeline; porting `df.clip(lower=bounds, axis=1)` from pandas to Beam.","solutions":["Use axis=0 or axis='index' when bounds are deferred frames.","Convert the bounds to a plain pandas Series/constant if they are small enough to materialize on the driver.","Rewrite as an elementwise expression: ddf.clip(lower=..., upper=...) per column via assign/transform."],"exampleFix":"// before\nddf.clip(lower=deferred_bounds, axis=1)\n\n// after\nddf.clip(lower=deferred_bounds, axis=0)  # or materialize bounds: clip(lower=bounds_pd_series)","handlingStrategy":"type-guard","validationCode":"from apache_beam.dataframe.frame_base import DeferredFrame\nif any(isinstance(kwargs.get(a), DeferredFrame) for a in ('lower', 'upper')) and axis not in (0, 'index'):\n    axis = 'index'","typeGuard":"def is_deferred_bound(v) -> bool:\n    from apache_beam.dataframe.frame_base import DeferredFrame\n    return isinstance(v, DeferredFrame)","tryCatchPattern":"from apache_beam.dataframe import frame_base\ntry:\n    out = ddf.clip(lower=lb, upper=ub, axis=axis)\nexcept frame_base.WontImplementError:\n    out = ddf.clip(lower=lb, upper=ub, axis='index')","preventionTips":["Use axis=0/'index' whenever clip bounds are deferred frames.","Materialize small bound series on the driver if column-wise clipping is needed.","Prefer elementwise expressions over axis tricks in Beam DataFrame code."],"tags":["pandas","apache-beam","dataframe","order-sensitive","axis"],"backgroundTag":"invalid-argument-value","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"}