{"record":{"id":"0a5b870b2a2e4187","repo":"apache/beam","slug":"cannot-specify-both-labels-and-index-columns","errorCode":null,"errorMessage":"Cannot specify both 'labels' and 'index'/'columns'","messagePattern":"Cannot specify both 'labels' and 'index'/'columns'","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/dataframe/frames.py","lineNumber":206,"sourceCode":"    else:\n      return 'indexes=[' + ', '.join(\n          '<unnamed>' if ix is None else repr(ix)\n          for ix in self.index.names) + ']'\n\n  __array__ = frame_base.wont_implement_method(\n      pd.Series, '__array__', reason=\"non-deferred-result\")\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 drop(self, labels, axis, index, columns, errors, **kwargs):\n    \"\"\"drop is not parallelizable when dropping from the index and\n    ``errors=\"raise\"`` is specified. It requires collecting all data on a single\n    node in order to detect if one of the index values is missing.\"\"\"\n    if labels is not None:\n      if index is not None or columns is not None:\n        raise ValueError(\"Cannot specify both 'labels' and 'index'/'columns'\")\n      if axis in (0, 'index'):\n        index = labels\n        columns = None\n      elif axis in (1, 'columns'):\n        index = None\n        columns = labels\n      else:\n        raise ValueError(\n            \"axis must be one of (0, 1, 'index', 'columns'), \"\n            \"got '%s'\" % axis)\n\n    if columns is not None:\n      # Compute the proxy based on just the columns that are dropped.\n      proxy = self._expr.proxy().drop(columns=columns, errors=errors)\n    else:\n      proxy = self._expr.proxy()\n\n    if index is not None and errors == 'raise':","sourceCodeStart":188,"sourceCodeEnd":224,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/dataframe/frames.py#L188-L224","documentation":"Beam DataFrames' drop() wraps pandas drop with a partitioning-aware implementation. pandas itself forbids passing 'labels' together with 'index'/'columns'; this library re-implements that validation and raises ValueError early so the conflict never reaches the underlying pandas proxy computation.","triggerScenarios":"Calling df.drop(labels=['a'], columns=1) or df.drop(labels='a', index='x') — i.e. supplying labels and either index or columns simultaneously, regardless of axis.","commonSituations":"Migrating code from pandas where the mixed call silently fails or is ambiguous; copy-pasted snippets mixing positional and keyword styles; refactor scripts that changed index= to labels= without removing the old keyword.","solutions":["Pass only one style: either labels= (with axis=) or index=/columns= alone","If dropping column labels, replace labels=...,axis=1 with columns=[...]","If dropping index labels, replace labels=...,axis=0 with index=[...]"],"exampleFix":"# before\ndf.drop(labels='col_a', axis=1, columns=['col_b'])\n# after\ndf.drop(columns=['col_a', 'col_b'])","handlingStrategy":"validation","validationCode":"def safe_drop(df, labels=None, axis=None, index=None, columns=None):\n    if labels is not None and (index is not None or columns is not None):\n        raise ValueError(\"pass either labels= (with axis) or index=/columns=, not both\")\n    return df.drop(labels=labels, axis=axis, index=index, columns=columns)","typeGuard":"def uses_mixed_drop_kwargs(kwargs):\n    return 'labels' in kwargs and ('index' in kwargs or 'columns' in kwargs)","tryCatchPattern":"try:\n    out = df.drop(labels=lbls, axis=axis)\nexcept ValueError as e:\n    logging.error(\"invalid drop() args: %s\", e)\n    out = df.drop(columns=lbls)  # fallback: assume column labels","preventionTips":["Prefer the explicit index=/columns= keywords over labels+axis","Never mix labels= with index=/columns=","Add a unit test for each drop() call shape used in your pipeline"],"tags":["python","apache-beam","dataframe","argument-validation"],"backgroundTag":"mutually-exclusive-options","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}