apache/beam · error · ValueError

axis must be one of (0, 1, 'index', 'columns'), got '%s'

Error message

axis must be one of (0, 1, 'index', 'columns'), got '%s'

What it means

When drop() is called with labels=, the axis argument determines whether labels refer to the index or columns. If axis is anything other than 0, 1, 'index', or 'columns', this ValueError is raised because the target of the drop cannot be determined.

Source

Thrown at sdks/python/apache_beam/dataframe/frames.py:214

  @frame_base.with_docs_from(pd.DataFrame)
  @frame_base.args_to_kwargs(pd.DataFrame)
  @frame_base.populate_defaults(pd.DataFrame)
  @frame_base.maybe_inplace
  def drop(self, labels, axis, index, columns, errors, **kwargs):
    """drop is not parallelizable when dropping from the index and
    ``errors="raise"`` is specified. It requires collecting all data on a single
    node in order to detect if one of the index values is missing."""
    if labels is not None:
      if index is not None or columns is not None:
        raise ValueError("Cannot specify both 'labels' and 'index'/'columns'")
      if axis in (0, 'index'):
        index = labels
        columns = None
      elif axis in (1, 'columns'):
        index = None
        columns = labels
      else:
        raise ValueError(
            "axis must be one of (0, 1, 'index', 'columns'), "
            "got '%s'" % axis)

    if columns is not None:
      # Compute the proxy based on just the columns that are dropped.
      proxy = self._expr.proxy().drop(columns=columns, errors=errors)
    else:
      proxy = self._expr.proxy()

    if index is not None and errors == 'raise':
      # In order to raise an error about missing index values, we'll
      # need to collect the entire dataframe.
      # TODO: This could be parallelized by putting index values in a
      # ConstantExpression and partitioning by index.
      requires = partitionings.Singleton(
          reason=(
              "drop(errors='raise', axis='index') is not currently "
              "parallelizable. This requires collecting all data on a single "

View on GitHub (pinned to 12126d8942)

Solutions

  1. Use one of axis=0, axis=1, axis='index', axis='columns'
  2. Prefer the explicit index= or columns= keywords and omit axis entirely
  3. Remember axis=1/'columns' drops columns; axis=0/'index' drops row labels

Example fix

# before
df.drop(labels='col_a', axis='col')
# after
df.drop(labels='col_a', axis='columns')
Defensive patterns

Strategy: validation

Validate before calling

VALID_AXES = (0, 1, 'index', 'columns')
if axis not in VALID_AXES:
    raise ValueError(f"axis must be one of {VALID_AXES}")
out = df.drop(labels=labels, axis=axis)

Type guard

def is_valid_axis(axis):
    return axis in (0, 1, 'index', 'columns')

Try / catch

try:
    out = df.drop(labels=labels, axis=axis)
except ValueError:
    out = df.drop(labels=labels, axis='columns' if str(axis).startswith('col') else 'index')

Prevention

When it happens

Trigger: df.drop(labels=['a'], axis='rows') or df.drop(labels=['a'], axis='column') — an axis string not in the accepted set, passed together with labels=.

Common situations: Typos like axis='row'/'cols'; porting from APIs that accept 'rows'/'columns-only' spellings; mixing up the axis convention (axis=1 means columns, not rows).

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


AI-assisted analysis of apache/beam@12126d8942 (2026-09-13). Data as JSON: /api/errors/8a5cbc563cb9b861. Report an issue: GitHub.