{"record":{"id":"b7218c3fcc49a7d8","repo":"pola-rs/polars","slug":"invalid-input-for-copy-copy-r","errorCode":null,"errorMessage":"invalid input for `copy`: {copy!r}","messagePattern":"invalid input for `copy`: (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/series/series.py","lineNumber":1492,"sourceCode":"        See Also\n        --------\n        __array_ufunc__\n        \"\"\"\n        # Cast String types to fixed-length string to support string ufuncs\n        # TODO: Use variable-length strings instead when NumPy 2.0.0 comes out:\n        # https://numpy.org/devdocs/reference/routines.dtypes.html#numpy.dtypes.StringDType\n        if dtype is None and not self.has_nulls() and self.dtype == String:\n            dtype = np.dtype(\"U\")\n\n        if copy is None:\n            writable, allow_copy = False, True\n        elif copy is True:\n            writable, allow_copy = True, True\n        elif copy is False:\n            writable, allow_copy = False, False\n        else:\n            msg = f\"invalid input for `copy`: {copy!r}\"\n            raise TypeError(msg)\n\n        arr = self.to_numpy(writable=writable, allow_copy=allow_copy)\n\n        if dtype is not None and dtype != arr.dtype:\n            if copy is False:\n                # TODO: Only raise when data must be copied\n                msg = f\"copy not allowed: cast from {arr.dtype} to {dtype} prohibited\"\n                raise RuntimeError(msg)\n\n            arr = arr.__array__(dtype)\n\n        return arr\n\n    def __array_ufunc__(\n        self, ufunc: np.ufunc, method: str_, *inputs: Any, **kwargs: Any\n    ) -> Series:\n        \"\"\"Numpy universal functions.\"\"\"\n        if self._s.n_chunks() > 1:","sourceCodeStart":1474,"sourceCodeEnd":1510,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/py-polars/src/polars/series/series.py#L1474-L1510","documentation":"Series.__array__ validates the `copy` keyword strictly: only True, False, or None are accepted (per the dataframe interchange convention). Any other truthy/falsy value (e.g. 1, 0, \"yes\") raises this TypeError at py-polars/src/polars/series/series.py:1492.","triggerScenarios":"Calling `series.to_numpy()`/`np.asarray(series, ...)` machinery or `series.__array__(dtype, copy=1)` with a non-bool copy value; passing copy from user config where an int was stored.","commonSituations":"Passing `copy=0`/`copy=1` from YAML/CLI config; older numpy interop code using integer flags; calling __array__ directly in custom converters.","solutions":["Pass a real boolean: `series.__array__(copy=True)` or `copy=False`","Coerce before calling: `copy=bool(copy)` — but ensure it maps to True/False, not 0/1","Omit copy (None) to let polars choose the cheapest path"],"exampleFix":"// before\narr = s.__array__(copy=1)  # TypeError\n// after\narr = s.__array__(copy=True)","handlingStrategy":"validation","validationCode":"if copy is not None and not isinstance(copy, bool):\n    raise ValueError(\"copy must be True, False, or None\")\narr = series.__array__(dtype=dtype, copy=copy)","typeGuard":"def is_bool_flag(copy: object) -> bool:\n    return copy is None or isinstance(copy, bool)","tryCatchPattern":"try:\n    arr = series.__array__(dtype=dtype, copy=copy)\nexcept TypeError as e:\n    if \"invalid input for `copy`\" in str(e):\n        arr = series.__array__(dtype=dtype, copy=bool(copy) and True or False)\n    else:\n        raise","preventionTips":["Always pass literal True/False for copy-like flags","Validate config-sourced flags with bool() coercion checks (0/1 fail here)","Read numpy interop signatures: copy is bool | None, not int"],"tags":["polars","python","numpy","copy-flag","type-error"],"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"}