{"record":{"id":"34ca96339088561b","repo":"pola-rs/polars","slug":"cannot-call-item-with-only-one-of-row-or-c","errorCode":null,"errorMessage":"cannot call `.item()` with only one of `row` or `column`","messagePattern":"cannot call `\\.item\\(\\)` with only one of `row` or `column`","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/dataframe/frame.py","lineNumber":1738,"sourceCode":"        >>> df.select((pl.col(\"a\") * pl.col(\"b\")).sum()).item()\n        32\n        >>> df.item(1, 1)\n        5\n        >>> df.item(2, \"b\")\n        6\n        \"\"\"\n        if row is None and column is None:\n            if self.shape != (1, 1):\n                msg = (\n                    'can only call `.item()` without \"row\" or \"column\" values if the '\n                    f\"DataFrame has a single element; shape={self.shape!r}\"\n                )\n                raise ValueError(msg)\n            return self._df.to_series(0).get_index(0)\n\n        elif row is None or column is None:\n            msg = \"cannot call `.item()` with only one of `row` or `column`\"\n            raise ValueError(msg)\n\n        s = (\n            self._df.to_series(column)\n            if isinstance(column, int)\n            else self._df.get_column(column)\n        )\n        return s.get_index_signed(row)\n\n    @deprecate_renamed_parameter(\"future\", \"compat_level\", version=\"1.1\")\n    def to_arrow(self, *, compat_level: CompatLevel | None = None) -> pa.Table:\n        \"\"\"\n        Collect the underlying arrow arrays in an Arrow Table.\n\n        This operation is mostly zero copy.\n\n        Data types that do copy:\n            - CategoricalType\n","sourceCodeStart":1720,"sourceCodeEnd":1756,"githubUrl":"https://github.com/pola-rs/polars/blob/df599052daf96e7a9cc30a3b0c6bd25d6947e3c0/py-polars/src/polars/dataframe/frame.py#L1720-L1756","documentation":"Raised by DataFrame.item() when exactly one of `row` and `column` is provided. The accessor contract is all-or-nothing: with no arguments it requires a 1x1 frame, and with both arguments it fetches a specific cell. A single argument is ambiguous (row of what? column of what?), so polars rejects it immediately rather than guessing a convention.","triggerScenarios":"`df.item(row=0)`, `df.item(None, 'col')`, `df.item(2)`, or `df.item(column='a')` — any call where precisely one of the two optional parameters is not None.","commonSituations":"Copy-paste from pandas `df.item()` habits mixed with `.iat[row, col]` muscle memory; refactoring code that used `df['col'][row]` into `.item()` and forgetting the second argument; passing row=None as a 'default' meaning 'any row'.","solutions":["Pass both arguments: `df.item(row, column)` with column as int index or name string","If you want a whole row, use `df.row(index)`; if you want a whole column, `df[column, row]` or `df.get_column(name)[row]`","If you meant the single element of a 1x1 frame, call `df.item()` with no arguments"],"exampleFix":"# before\nv = df.item(0)          # only row given\n\n# after\nv = df.item(0, 'col')   # row and column\n# or the whole row:\nrow = df.row(0)","handlingStrategy":"validation","validationCode":"if (row is None) != (column is None):\n    raise ValueError('.item() needs both row and column, or neither')\nvalue = df.item(row, column)","typeGuard":"def item_args_ok(row: int | None, column: int | str | None) -> bool:\n    \"\"\"Both None or both set — anything else makes .item() ambiguous.\"\"\"\n    return (row is None) == (column is None)","tryCatchPattern":"try:\n    v = df.item(row, column)\nexcept ValueError as e:\n    if 'only one of' in str(e):\n        v = df.row(row) if column is None else df.get_column(column).to_list()\n    else:\n        raise","preventionTips":["Treat .item()'s row/column as a pair: always pass both or neither","For whole-row access use df.row(i); for whole-column use df[col]","Lint callsites where one of the two kwargs is conditionally None"],"tags":["dataframe","item","argument-mismatch","validation"],"backgroundTag":null,"analyzedSha":"df599052daf96e7a9cc30a3b0c6bd25d6947e3c0","analyzedAt":"2026-08-16T12:10:03.978Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}