{"record":{"id":"a2c3a38f3248d5f4","repo":"apache/beam","slug":"axis-must-be-one-of-index-0-columns-1-got-axis-r","errorCode":null,"errorMessage":"axis must be one of ('index', 0, 'columns', 1). got {axis!r}.","messagePattern":"axis must be one of \\('index', 0, 'columns', 1\\)\\. got (.+?)\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/dataframe/frames.py","lineNumber":1064,"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  def xs(self, key, axis, level, **kwargs):\n    \"\"\"Note that ``xs(axis='index')`` will raise a ``KeyError`` at execution\n    time if the key does not exist in the index.\"\"\"\n\n    if axis in ('columns', 1):\n      # Special case for axis=columns. This is a simple project that raises a\n      # KeyError at construction time for missing columns.\n      return frame_base.DeferredFrame.wrap(\n          expressions.ComputedExpression(\n              'xs', lambda df: df.xs(key, axis=axis, **kwargs), [self._expr],\n              requires_partition_by=partitionings.Arbitrary(),\n              preserves_partition_by=partitionings.Arbitrary()))\n    elif axis not in ('index', 0):\n      # Make sure that user's axis is valid\n      raise ValueError(\n          \"axis must be one of ('index', 0, 'columns', 1). \"\n          f\"got {axis!r}.\")\n\n    if not isinstance(key, tuple):\n      key_size = 1\n      key_series = pd.Series([key], index=[key])\n    else:\n      key_size = len(key)\n      key_series = pd.Series([key], pd.MultiIndex.from_tuples([key]))\n\n    key_expr = expressions.ConstantExpression(\n        key_series, proxy=key_series.iloc[:0])\n\n    if level is None:\n      reindexed = self\n    else:\n      if not isinstance(level, list):\n        level = [level]","sourceCodeStart":1046,"sourceCodeEnd":1082,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/dataframe/frames.py#L1046-L1082","documentation":"xs() in Beam DataFrames supports selecting from either the index (axis=0/'index') or, in the branch that raises, validates that any other axis value is at least a legal pandas axis before delegating. An axis outside ('index', 0, 'columns', 1) is rejected with ValueError.","triggerScenarios":"df.xs('k', axis='rows') or df.xs('k', axis=2) — an invalid axis spelling/type passed to xs; note axis=1/'columns' is also not implemented on the index path (only 'index'/0 is handled before this check).","commonSituations":"Typos like 'row'/'Rows'; integer/string confusion after refactoring; copying pandas snippets that used axis=1 for column-level xs without realizing the Beam path differs.","solutions":["Use axis='index' or axis=0 when selecting index levels with xs","Use axis='columns' or axis=1 only if selecting from columns, and verify support","Validate axis values against the allowed set before calling"],"exampleFix":"// before\ndf.xs('L1', axis='rows')\n// after\ndf.xs('L1', axis='index')","handlingStrategy":"validation","validationCode":"if axis not in ('index', 0, 'columns', 1):\n    raise ValueError(f\"invalid xs axis: {axis!r}\")\nout = df.xs(key, axis=axis)","typeGuard":"def valid_xs_axis(axis):\n    return axis in ('index', 0, 'columns', 1)","tryCatchPattern":"try:\n    out = df.xs(key, axis=axis)\nexcept ValueError:\n    out = df.xs(key, axis='index')  # index selection is the supported default","preventionTips":["Use 'index'/0 for index-level xs in Beam","Avoid 'rows'/'cols' spellings","Check Beam xs docs before using axis=1; column xs may be unsupported"],"tags":["python","apache-beam","dataframe","axis-argument"],"backgroundTag":"invalid-enum-value","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"}