apache/beam · warning

Performing a numeric aggregation, {base_func!r}, on Series {

Error message

Performing a numeric aggregation, {base_func!r}, on Series {self._expr.proxy().name!r} with non-numeric type {self.dtype!r}. This can result in runtime errors or surprising results.

What it means

Beam DataFrames (apache_beam.dataframe) emits this warning when a numeric aggregation function (e.g. sum, mean) is applied to a DeferredSeries whose dtype is non-numeric. pandas would either fail at runtime or coerce with surprising results, so Beam warns eagerly at pipeline-construction time.

Source

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

    if isinstance(func, list) and len(func) > 1:
      # level arg is ignored for multiple aggregations
      _ = kwargs.pop('level', None)

      # Aggregate with each method separately, then stick them all together.
      rows = [self.agg([f], *args, **kwargs) for f in func]
      return frame_base.DeferredFrame.wrap(
          expressions.ComputedExpression(
              'join_aggregate', lambda *rows: pd.concat(rows),
              [row._expr for row in rows]))
    else:
      # We're only handling a single column. It could be 'func' or ['func'],
      # which produce different results. 'func' produces a scalar, ['func']
      # produces a single element Series.
      base_func = func[0] if isinstance(func, list) else func

      if (_is_numeric(base_func) and
          not pd.core.dtypes.common.is_numeric_dtype(self.dtype)):
        warnings.warn(
            f"Performing a numeric aggregation, {base_func!r}, on "
            f"Series {self._expr.proxy().name!r} with non-numeric type "
            f"{self.dtype!r}. This can result in runtime errors or surprising "
            "results.")

      if 'level' in kwargs:
        # Defer to groupby.agg for level= mode
        return self.groupby(
            level=kwargs.pop('level'), axis=axis).agg(func, *args, **kwargs)

      singleton_reason = None
      if 'min_count' in kwargs:
        # Eagerly generate a proxy to make sure min_count is a valid argument
        # for this aggregation method
        _ = self._expr.proxy().agg(func, axis, *args, **kwargs)

        singleton_reason = (
            "Aggregation with min_count= requires collecting all data on a "

View on GitHub (pinned to 12126d8942)

Solutions

  1. Convert the column to a numeric dtype before aggregating: s.astype('float64') or pd.to_numeric.
  2. Verify the inferred dtype with print(df.dtypes) before building the aggregation.
  3. Fix the read/parse transform so the column is parsed as numeric from the source.
  4. If intentional, suppress the warning explicitly (warnings.filterwarnings) after verifying semantics.

Example fix

# before
result = df['amount'].sum()  # dtype object
# after
df['amount'] = pd.to_numeric(df['amount'])
result = df['amount'].sum()
Defensive patterns

Strategy: type-guard

Validate before calling

if not pd.api.types.is_numeric_dtype(df['amount'].dtype):
    df['amount'] = pd.to_numeric(df['amount'], errors='raise')

Type guard

def is_numeric_series(s) -> bool:
  import pandas as pd
  return pd.api.types.is_numeric_dtype(s.dtype)

Try / catch

import warnings
with warnings.catch_warnings(record=True) as caught:
    warnings.simplefilter('always')
    result = df['col'].sum()
for w in caught:
    if 'numeric aggregation' in str(w.message):
        raise TypeError('Non-numeric dtype passed to numeric aggregation')

Prevention

When it happens

Trigger: Calling series.sum()/mean()/max() (or aggregate with a numeric base_func) on a DeferredSeries whose proxy dtype is str, object, datetime, bool-adjacent non-numeric, etc.

Common situations: CSV/JSON reads inferring object/string dtypes that the developer assumed were numeric; forgetting astype() after a read transform; aggregating an id or code column by mistake.

Related errors


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