{"record":{"id":"9beda497b4de2fcd","repo":"apache/beam","slug":"performing-a-numeric-aggregation-base-func-r-on-series-self","errorCode":null,"errorMessage":"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.","messagePattern":"Performing a numeric aggregation, (.+?), on Series (.+?) with non-numeric type (.+?)\\. This can result in runtime errors or surprising results\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"sdks/python/apache_beam/dataframe/frames.py","lineNumber":2035,"sourceCode":"    if isinstance(func, list) and len(func) > 1:\n      # level arg is ignored for multiple aggregations\n      _ = kwargs.pop('level', None)\n\n      # Aggregate with each method separately, then stick them all together.\n      rows = [self.agg([f], *args, **kwargs) for f in func]\n      return frame_base.DeferredFrame.wrap(\n          expressions.ComputedExpression(\n              'join_aggregate', lambda *rows: pd.concat(rows),\n              [row._expr for row in rows]))\n    else:\n      # We're only handling a single column. It could be 'func' or ['func'],\n      # which produce different results. 'func' produces a scalar, ['func']\n      # produces a single element Series.\n      base_func = func[0] if isinstance(func, list) else func\n\n      if (_is_numeric(base_func) and\n          not pd.core.dtypes.common.is_numeric_dtype(self.dtype)):\n        warnings.warn(\n            f\"Performing a numeric aggregation, {base_func!r}, on \"\n            f\"Series {self._expr.proxy().name!r} with non-numeric type \"\n            f\"{self.dtype!r}. This can result in runtime errors or surprising \"\n            \"results.\")\n\n      if 'level' in kwargs:\n        # Defer to groupby.agg for level= mode\n        return self.groupby(\n            level=kwargs.pop('level'), axis=axis).agg(func, *args, **kwargs)\n\n      singleton_reason = None\n      if 'min_count' in kwargs:\n        # Eagerly generate a proxy to make sure min_count is a valid argument\n        # for this aggregation method\n        _ = self._expr.proxy().agg(func, axis, *args, **kwargs)\n\n        singleton_reason = (\n            \"Aggregation with min_count= requires collecting all data on a \"","sourceCodeStart":2017,"sourceCodeEnd":2053,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/dataframe/frames.py#L2017-L2053","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"# before\nresult = df['amount'].sum()  # dtype object\n# after\ndf['amount'] = pd.to_numeric(df['amount'])\nresult = df['amount'].sum()","handlingStrategy":"type-guard","validationCode":"if not pd.api.types.is_numeric_dtype(df['amount'].dtype):\n    df['amount'] = pd.to_numeric(df['amount'], errors='raise')","typeGuard":"def is_numeric_series(s) -> bool:\n  import pandas as pd\n  return pd.api.types.is_numeric_dtype(s.dtype)","tryCatchPattern":"import warnings\nwith warnings.catch_warnings(record=True) as caught:\n    warnings.simplefilter('always')\n    result = df['col'].sum()\nfor w in caught:\n    if 'numeric aggregation' in str(w.message):\n        raise TypeError('Non-numeric dtype passed to numeric aggregation')","preventionTips":["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')."],"tags":["python","pandas","dataframe","dtype","beam"],"backgroundTag":"dtype-mismatch","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"}