{"record":{"id":"ad62053c38d2f7ed","repo":"apache/beam","slug":"op-must-be-one-of-idxmax-idxmin-got-op-r","errorCode":null,"errorMessage":"op must be one of ('idxmax', 'idxmin'). got {op!r}.","messagePattern":"op must be one of \\('idxmax', 'idxmin'\\)\\. got (.+?)\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/dataframe/frames.py","lineNumber":1482,"sourceCode":"      base=pd.DataFrame,\n      requires_partition_by=partitionings.Arbitrary(),\n      preserves_partition_by=partitionings.Singleton())\n  add_prefix = frame_base._proxy_method(\n      'add_prefix',\n      base=pd.DataFrame,\n      requires_partition_by=partitionings.Arbitrary(),\n      preserves_partition_by=partitionings.Singleton())\n\n  info = frame_base.wont_implement_method(\n      pd.Series, 'info', reason=\"non-deferred-result\")\n\n  def _idxmaxmin_helper(self, op, **kwargs):\n    if op == 'idxmax':\n      func = pd.Series.idxmax\n    elif op == 'idxmin':\n      func = pd.Series.idxmin\n    else:\n      raise ValueError(\n          \"op must be one of ('idxmax', 'idxmin'). \"\n          f\"got {op!r}.\")\n\n    def compute_idx(s):\n      index = func(s, **kwargs)\n      if pd.isna(index):\n        return s\n      else:\n        return s.loc[[index]]\n\n    # Avoids empty Series error when evaluating proxy\n    index_dtype = self._expr.proxy().index.dtype\n    index = pd.Index([], dtype=index_dtype)\n    proxy = self._expr.proxy().copy()\n    proxy.index = index\n    proxy = pd.concat([\n        proxy,\n        pd.Series([1], index=np.asarray(['0']).astype(proxy.index.dtype))","sourceCodeStart":1464,"sourceCodeEnd":1500,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/dataframe/frames.py#L1464-L1500","documentation":"apache_beam.dataframe (the pandas-on-Beam API) implements idxmax/idxmin via a single internal helper _idxmaxmin_helper that dispatches on the op string. The helper only accepts 'idxmax' or 'idxmin'; any other op value means an internal dispatch bug, since users call idxmin()/idxmax() which hardcode the op. This ValueError guards against the helper being invoked incorrectly.","triggerScenarios":"Calling _idxmaxmin_helper directly with an op value other than 'idxmax' or 'idxmin' (e.g. a typo, None, or a patched/monkey-patched dispatch); the public idxmin/idxmax methods pass literal values so this is effectively unreachable through the public API.","commonSituations":"Contributors extending the frames module who add a new idx-style op but pass a wrong string; debugging code that introspects or wraps internal helpers; fat-fingering op='idxmax' vs 'idxmax ' in custom wrappers.","solutions":["Use the public API: call df.idxmax() or series.idxmin() instead of invoking _idxmaxmin_helper manually.","If writing a wrapper, pass only the literal strings 'idxmax' or 'idxmin' as op.","Check for typos/whitespace in the op value; print repr(op) to verify.","If this appears through normal idxmax/idxmin usage, file a bug against apache_beam."],"exampleFix":"// before\nfunc = getattr(pd.Series, op)  # op could be anything\nhelper(op)\n// after\nif op in ('idxmax', 'idxmin'):\n    _idxmaxmin_helper(op)\nelse:\n    df.idxmax()  # use the public method","handlingStrategy":"type-guard","validationCode":"if op not in ('idxmax', 'idxmin'):\n    raise ValueError(f'op must be idxmax or idxmin, got {op!r}')","typeGuard":"def is_valid_idx_op(op) -> bool:\n    return op in ('idxmax', 'idxmin')","tryCatchPattern":"try:\n    result = df.idxmax()\nexcept ValueError as e:\n    logger.error('idx op dispatch failed: %s', e)\n    result = None","preventionTips":["Always call the public idxmax()/idxmin() methods instead of the internal helper.","Never construct the op string dynamically; use literals."],"tags":["python","apache-beam","dataframe","invalid-argument-value"],"backgroundTag":"invalid-enum-value","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"}