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
- Convert the column to a numeric dtype before aggregating: s.astype('float64') or pd.to_numeric.
- Verify the inferred dtype with print(df.dtypes) before building the aggregation.
- Fix the read/parse transform so the column is parsed as numeric from the source.
- 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
- Assert dtypes right after read transforms (print(df.dtypes)).
- Apply pd.to_numeric or astype before any sum/mean/max on parsed columns.
- Avoid aggregating id/code/string columns by mistake.
- Promote this warning to an error in tests via warnings.simplefilter('error').
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
- include_indexes=True for a Series input. Note that this para
- Cannot infer a proxy because the input PCollection does not
- Proxy '{proxy}' has unsupported type '{type(proxy)}'
- concat(ignore_index)
- concat(levels)
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/9beda497b4de2fcd.
Report an issue: GitHub.