{"record":{"id":"b206d3ee2a9a8096","repo":"pola-rs/polars","slug":"compat-level-has-invalid-type-qualified-type-n-b206d3","errorCode":null,"errorMessage":"`compat_level` has invalid type: {qualified_type_name(compat_level)!r}","messagePattern":"`compat_level` has invalid type: (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/series/series.py","lineNumber":5231,"sourceCode":"        --------\n        >>> s = pl.Series(\"a\", [1, 2, 3])\n        >>> s = s.to_arrow()\n        >>> s\n        <pyarrow.lib.Int64Array object at ...>\n        [\n          1,\n          2,\n          3\n        ]\n        \"\"\"\n        compat_level_py: int | bool\n        if compat_level is None:\n            compat_level_py = False\n        elif isinstance(compat_level, CompatLevel):\n            compat_level_py = compat_level._version\n        else:\n            msg = f\"`compat_level` has invalid type: {qualified_type_name(compat_level)!r}\"\n            raise TypeError(msg)\n        return self._s.to_arrow(compat_level_py)\n\n    def to_pandas(\n        self, *, use_pyarrow_extension_array: bool = False, **kwargs: Any\n    ) -> pd.Series[Any]:\n        \"\"\"\n        Convert this Series to a pandas Series.\n\n        This operation copies data if `use_pyarrow_extension_array` is not enabled.\n\n        Parameters\n        ----------\n        use_pyarrow_extension_array\n            Use a PyArrow-backed extension array instead of a NumPy array for the pandas\n            Series. This allows zero copy operations and preservation of null values.\n            Subsequent operations on the resulting pandas Series may trigger conversion\n            to NumPy if those operations are not supported by PyArrow compute functions.\n        **kwargs","sourceCodeStart":5213,"sourceCodeEnd":5249,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/py-polars/src/polars/series/series.py#L5213-L5249","documentation":"Type discrimination on the `compat_level` argument to Series.to_arrow. The parameter accepts only None (meaning 'use defaults', mapped to False) or a CompatLevel instance (whose internal version number is extracted); any other type falls into the else branch and is rejected, with the qualified type name reported so the caller can see what was actually passed.","triggerScenarios":"srs.to_arrow(compat_level=\"oldest\") or to_arrow(compat_level=1) instead of passing pl.CompatLevel.oldest() / pl.CompatLevel.newest().","commonSituations":"Copying API style from to_pandas/use_pyarrow options; guessing that compat_level takes a string like other polars options.","solutions":["Pass a CompatLevel instance: pl.CompatLevel.oldest() or pl.CompatLevel.newest()","Omit the argument (default None) if no specific compat level is needed","Check the signature in your polars version; older versions have no compat_level param"],"exampleFix":"// before\nsrs.to_arrow(compat_level=\"oldest\")\n// after\nsrs.to_arrow(compat_level=pl.CompatLevel.oldest())","handlingStrategy":"type-guard","validationCode":"assert compat_level is None or isinstance(compat_level, pl.CompatLevel), 'compat_level must be None or pl.CompatLevel'","typeGuard":"def valid_compat_level(cl) -> bool:\n    return cl is None or isinstance(cl, pl.CompatLevel)","tryCatchPattern":"try:\n    tbl = srs.to_arrow(compat_level=compat_level)\nexcept TypeError:\n    tbl = srs.to_arrow()","preventionTips":["Always use pl.CompatLevel.oldest()/newest() for compat_level","Don't pass strings/ints where enums are specified","Check the function signature in your polars version"],"tags":["polars","type-error","to-arrow","argument-validation"],"backgroundTag":"invalid-argument-value","analyzedSha":"fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e","analyzedAt":"2026-09-18T22:14:11.667Z","contentChangedAt":"2026-09-18T22:14:11.667Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}