{"record":{"id":"3e9474816ecab7ef","repo":"apache/beam","slug":"no-aggregation-functions-specified","errorCode":null,"errorMessage":"No aggregation functions specified","messagePattern":"No aggregation functions specified","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/dataframe/frames.py","lineNumber":4716,"sourceCode":"  keyword arguments and combines the results into a single DataFrame.\n\n  Args:\n      gb: The groupby instance (DeferredGroupBy).\n      *args: Additional positional arguments passed to the aggregation funcs.\n      **kwargs: A dictionary where each key is the column name to aggregate,\n                the value is a tuple containing the input column name and\n                the aggregation function to apply.\n\n  Returns:\n      DeferredDataFrame: A DataFrame that contains the aggregated results of\n                          all specified columns.\n\n  Raises:\n      ValueError: If no aggregation functions are provided in the `kwargs`.\n      NotImplementedError: If the aggregation function type is unsupported.\n  \"\"\"\n  if not kwargs:\n    raise ValueError(\"No aggregation functions specified\")\n\n  # Handle dictionary-like input for aggregation.\n  result_columns, result_frames = [], []\n  for col_name, (input_col, agg_fn) in kwargs.items():\n    frame = _handle_agg_function(\n      gb[input_col], agg_fn, f\"agg_{col_name}\", *args\n    )\n    result_frames.append(frame)\n    result_columns.append(col_name)\n\n  # Combine all the resulting DeferredDataFrames into a single DataFrame.\n  return DeferredDataFrame(\n      expressions.ComputedExpression(\n          \"agg\",\n          lambda *results: pd.concat(results, axis=1, keys=result_columns),\n          [frame._expr for frame in result_frames],\n          requires_partition_by=partitionings.Index(),\n          preserves_partition_by=partitionings.Singleton(),","sourceCodeStart":4698,"sourceCodeEnd":4734,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/dataframe/frames.py#L4698-L4734","documentation":"The generic groupby aggregation helper in frames.py raises ValueError when kwargs contains no aggregation functions. Beam needs at least one column->(input, function) mapping to build the aggregation expression.","triggerScenarios":"Calling gb.agg() (or the internal _aggregate with empty kwargs) with no column/function pairs, e.g. df.groupby('k').agg() on a Beam deferred DataFrame.","commonSituations":"Building kwargs dynamically (loop/conditionals) that ends up empty; refactoring that removed all aggregation specs; passing only positional args that the helper ignores.","solutions":["Provide at least one aggregation, e.g. gb.agg(mean_v=('v', 'mean')).","Validate the kwargs dict is non-empty before calling: `if not aggs: raise ...` or skip the call.","Ensure your dynamic kwargs construction actually populates entries for every column you intend to aggregate."],"exampleFix":"# before\ncols = {c: a for c, a in specs.items() if cond(c)}\ndf.groupby('k').agg(**cols)  # cols may be {}\n# after\nif not cols:\n    cols = {c: ('mean',) for c in df.columns if c != 'k'}\ndf.groupby('k').agg(**cols)","handlingStrategy":"validation","validationCode":"if not agg_kwargs:\n    raise ValueError('agg requires at least one aggregation spec')\nbeam_df.groupby('k').agg(**agg_kwargs)","typeGuard":"def has_aggs(kwargs: dict) -> bool:\n    return bool(kwargs)","tryCatchPattern":"try:\n    out = beam_df.groupby('k').agg(**agg_kwargs)\nexcept ValueError as e:\n    if 'No aggregation functions specified' in str(e):\n        logging.warning('Empty agg spec; skipping aggregation')\n        out = beam_df","preventionTips":["Validate dynamically-built kwargs dicts are non-empty before calling agg.","Provide default aggregation specs when conditional construction yields nothing.","Cover agg call sites with construction-time tests using empty proxy data."],"tags":["apache-beam","dataframe","value-error","aggregation"],"backgroundTag":"empty-required-field","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"}