{"record":{"id":"7695380b3fab53bd","repo":"apache/beam","slug":"numeric-aggregation-func-r-on-a-dataframe-containing-non","errorCode":null,"errorMessage":"Numeric aggregation ({func!r}) on a DataFrame containing non-numeric columns ({*nonnumeric_columns,!r} is not supported, unless `numeric_only=` is specified.\nUse `numeric_only=True` to only aggregate over numeric columns.\nUse `numeric_only=False` to aggregate over all columns. Note this is not recommended, as it could result in execution time errors.","messagePattern":"Numeric aggregation \\((.+?)\\) on a DataFrame containing non-numeric columns \\((.+?) is not supported, unless `numeric_only=` is specified\\.\nUse `numeric_only=True` to only aggregate over numeric columns\\.\nUse `numeric_only=False` to aggregate over all columns\\. Note this is not recommended, as it could result in execution time errors\\.","errorType":"exception","errorClass":"WontImplementError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/dataframe/frames.py","lineNumber":2935,"sourceCode":"\n      if isinstance(proxy, pd.DataFrame):\n        projected = self[list(proxy.columns)]\n      elif isinstance(proxy, pd.Series):\n        projected = self[list(proxy.index)]\n      else:\n        projected = self\n\n      nonnumeric_columns = [name for (name, dtype) in projected.dtypes.items()\n                            if not\n                            pd.core.dtypes.common.is_numeric_dtype(dtype)]\n\n      if _is_numeric(func) and nonnumeric_columns:\n        if 'numeric_only' in kwargs and kwargs['numeric_only'] is False:\n          # User has opted in to execution with non-numeric columns, they\n          # will accept runtime errors\n          pass\n        else:\n          raise frame_base.WontImplementError(\n              f\"Numeric aggregation ({func!r}) on a DataFrame containing \"\n              f\"non-numeric columns ({*nonnumeric_columns,!r} is not \"\n              \"supported, unless `numeric_only=` is specified.\\n\"\n              \"Use `numeric_only=True` to only aggregate over numeric \"\n              \"columns.\\nUse `numeric_only=False` to aggregate over all \"\n              \"columns. Note this is not recommended, as it could result in \"\n              \"execution time errors.\")\n\n      for key in PROJECT_KWARGS:\n        if key in kwargs:\n          kwargs.pop(key)\n\n      if not isinstance(func, dict):\n        col_names = list(projected._expr.proxy().columns)\n        func_by_col = {col: func for col in col_names}\n      else:\n        func_by_col = func\n        col_names = list(func.keys())","sourceCodeStart":2917,"sourceCodeEnd":2953,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/dataframe/frames.py#L2917-L2953","documentation":"Numeric aggregations (mean, sum, etc.) on a DeferredDataFrame that contains non-numeric columns require an explicit numeric_only argument. Pandas' silent column-dropping behavior is version-dependent and error-prone, so Beam raises WontImplementError unless the user opts in with numeric_only=True (aggregate numeric columns only) or numeric_only=False (attempt all columns, accepting possible runtime errors).","triggerScenarios":"Calling an aggregation like ddf.mean(), ddf.sum(), ddf.median() on a frame with non-numeric columns, without passing numeric_only, or with numeric_only=None.","commonSituations":"Frames built from CSV/JSON with a stray string column (e.g. an 'id' or 'notes' column) mixed into numeric data; pandas 2.x changed default numeric_only behavior, breaking migrated aggregation code.","solutions":["Pass numeric_only=True: ddf.mean(numeric_only=True).","Select only numeric columns before aggregating: ddf[['a', 'b']].mean().","Convert or drop non-numeric columns first (e.g. pd.to_numeric or del ddf['str_col']).","Pass numeric_only=False only if you accept possible execution-time errors on non-numeric columns."],"exampleFix":"// before\nddf.mean()\n\n// after\nddf.mean(numeric_only=True)\n# or\nddf[['col1', 'col2']].mean()","handlingStrategy":"validation","validationCode":"numeric_cols = [c for c in ddf.columns if pd.api.types.is_numeric_dtype(schema_dtypes[c])]\nif len(numeric_cols) < len(ddf.columns):\n    result = ddf[numeric_cols].mean()  # or ddf.mean(numeric_only=True)","typeGuard":"def needs_numeric_only(columns, dtypes) -> bool:\n    return any(not pd.api.types.is_numeric_dtype(t) for t in dtypes)","tryCatchPattern":"from apache_beam.dataframe import frame_base\ntry:\n    out = ddf.mean()\nexcept frame_base.WontImplementError:\n    out = ddf.mean(numeric_only=True)","preventionTips":["Always pass numeric_only explicitly to aggregations on mixed-type frames.","Clean/coerce non-numeric columns (pd.to_numeric, drops) before aggregating.","Check the frame's dtypes/schema when loading CSV/JSON sources."],"tags":["pandas","apache-beam","dataframe","aggregation","numeric-only"],"backgroundTag":"missing-required-argument","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}