{"record":{"id":"82cd27db30e66a9b","repo":"pola-rs/polars","slug":"one-of-index-or-by-predicate-must-be-set","errorCode":null,"errorMessage":"one of `index` or `by_predicate` must be set","messagePattern":"one of `index` or `by_predicate` must be set","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"info","filePath":"py-polars/src/polars/dataframe/frame.py","lineNumber":11895,"sourceCode":"                msg = f\"expected `by_predicate` to be an expression, got {qualified_type_name(by_predicate)!r}\"\n                raise TypeError(msg)\n            rows = self.filter(by_predicate).rows()\n            n_rows = len(rows)\n            if n_rows > 1:\n                msg = f\"predicate <{by_predicate!s}> returned {n_rows} rows\"\n                raise TooManyRowsReturnedError(msg)\n            elif n_rows == 0:\n                msg = f\"predicate <{by_predicate!s}> returned no rows\"\n                raise NoRowsReturnedError(msg)\n\n            row = rows[0]\n            if named:\n                return dict(zip(self.columns, row, strict=True))\n            else:\n                return row\n        else:\n            msg = \"one of `index` or `by_predicate` must be set\"\n            raise ValueError(msg)\n\n    @overload\n    def rows(self, *, named: Literal[False] = ...) -> list[tuple[Any, ...]]: ...\n\n    @overload\n    def rows(self, *, named: Literal[True]) -> list[dict[str, Any]]: ...\n\n    def rows(\n        self, *, named: bool = False\n    ) -> list[tuple[Any, ...]] | list[dict[str, Any]]:\n        \"\"\"\n        Returns all data in the DataFrame as a list of rows of python-native values.\n\n        By default, each row is returned as a tuple of values given in the same order\n        as the frame columns. Setting `named=True` will return rows of dictionaries\n        instead.\n\n        Parameters","sourceCodeStart":11877,"sourceCodeEnd":11913,"githubUrl":"https://github.com/pola-rs/polars/blob/df599052daf96e7a9cc30a3b0c6bd25d6947e3c0/py-polars/src/polars/dataframe/frame.py#L11877-L11913","documentation":"A defensive ValueError at the end of DataFrame.row's dispatch chain, raised if the method reaches row extraction with neither `index` nor `by_predicate` set. In the current implementation this branch is effectively unreachable through the public API: the both-None case is fully handled by the first branch (height == 1 -> index = 0, otherwise the 'single row' error). It exists to make the function total and to catch future signature changes or reflective/monkey-patched calls that bypass the normal entry conditions.","triggerScenarios":"Not producible by normal calls to DataFrame.row in this version; conceivable only via reflection, monkey-patching the method, or a future polars version that alters the early branches while keeping this fallback.","commonSituations":"Effectively none in practice — if you see this error, suspect a patched/overridden row method or a non-standard polars build; otherwise treat it as an internal invariant violation worth reporting upstream.","solutions":["Pass an explicit selector (index=0 or by_predicate=pl.col(...)) — this also future-proofs the call","Check for monkey-patches or subclasses overriding row() in your codebase","If it reproduces on stock polars, report it as a bug with a minimal reproducer"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if index is None and by_predicate is None and df.height != 1:\n    raise ValueError(f'row() needs index or by_predicate; frame shape is {df.shape}')\nrow = df.row(index=index, by_predicate=by_predicate)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pass an explicit selector (index=0 or by_predicate=...) so no dispatch fallback is ever relied on","If this error ever fires on stock polars, treat it as an internal bug and report it upstream with a reproducer","Audit subclasses/monkey-patches of DataFrame.row in your codebase if it appears"],"tags":["polars","dataframe","row","defensive-code","unreachable","valueerror"],"backgroundTag":null,"analyzedSha":"df599052daf96e7a9cc30a3b0c6bd25d6947e3c0","analyzedAt":"2026-08-16T12:10:03.978Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}