{"record":{"id":"4a30600e676cee4c","repo":"pola-rs/polars","slug":"the-truth-value-of-a-series-is-ambiguous-n-nhere-a","errorCode":null,"errorMessage":"the truth value of a Series is ambiguous\\n\\nHere are some things you might want to try:\\n- instead of `if s`, use `if not s.is_empty()`\\n- instead of `s1 and s2`, use `s1 & s2`\\n- instead of `s1 or s2`, use `s1 | s2`\\n- instead of `s in [y, z]`, use `s.is_in([y, z])`\\n","messagePattern":"the truth value of a Series is ambiguous\\\\n\\\\nHere are some things you might want to try:\\\\n- instead of `if s`, use `if not s\\.is_empty\\(\\)`\\\\n- instead of `s1 and s2`, use `s1 & s2`\\\\n- instead of `s1 or s2`, use `s1 \\| s2`\\\\n- instead of `s in \\[y, z\\]`, use `s\\.is_in\\(\\[y, z\\]\\)`\\\\n","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/series/series.py","lineNumber":637,"sourceCode":"        Examples\n        --------\n        >>> s = pl.Series(\"a\", [1, 2, 3])\n        >>> s.shape\n        (3,)\n        \"\"\"\n        return (self._s.len(),)\n\n    def __bool__(self) -> NoReturn:\n        msg = (\n            \"the truth value of a Series is ambiguous\"\n            \"\\n\\n\"\n            \"Here are some things you might want to try:\\n\"\n            \"- instead of `if s`, use `if not s.is_empty()`\\n\"\n            \"- instead of `s1 and s2`, use `s1 & s2`\\n\"\n            \"- instead of `s1 or s2`, use `s1 | s2`\\n\"\n            \"- instead of `s in [y, z]`, use `s.is_in([y, z])`\\n\"\n        )\n        raise TypeError(msg)\n\n    def __getstate__(self) -> bytes:\n        return self._s.__getstate__()\n\n    def __setstate__(self, state: bytes) -> None:\n        self._s = Series()._s  # Initialize with a dummy\n        self._s.__setstate__(state)\n\n    def __str__(self) -> str_:\n        s_repr: str = self._s.as_str()\n        return s_repr.replace(\"Series\", f\"{self.__class__.__name__}\", 1)\n\n    def __repr__(self) -> str_:\n        return self.__str__()\n\n    def __len__(self) -> int:\n        return self.len()\n","sourceCodeStart":619,"sourceCodeEnd":655,"githubUrl":"https://github.com/pola-rs/polars/blob/68506541d2de983056c9eb244e1ea05fab377dfc/py-polars/src/polars/series/series.py#L619-L655","documentation":"Error \"the truth value of a Series is ambiguous\\n\\nHere are some things you might want to try:\\n- instead of `if s`, use `if not s.is_empty()`\\n- instead of `s1 and s2`, use `s1 & s2`\\n- instead of `s1 or s2`, use `s1 | s2`\\n- instead of `s in [y, z]`, use `s.is_in([y, z])`\\n\" thrown in pola-rs/polars.","triggerScenarios":"Thrown at py-polars/src/polars/series/series.py:752 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Follow the suggestions in the message: use `s.is_empty()`, `&`/`|` instead of `and`/`or`, and `s.is_in([...])` instead of `in`."],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"68506541d2de983056c9eb244e1ea05fab377dfc","analyzedAt":"2026-08-19T12:15:06.350Z","contentChangedAt":"2026-08-19T12:15:06.350Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}