{"record":{"id":"50311348372f0197","repo":"pola-rs/polars","slug":"cannot-convert-dataframe-to-target-mixed-type-c","errorCode":null,"errorMessage":"cannot convert DataFrame to {target} (mixed type columns result in `object` dtype)\\n{df.schema!r}","messagePattern":"cannot convert DataFrame to (.+?) \\(mixed type columns result in `object` dtype\\)\\\\n(.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/ml/utilities.py","lineNumber":29,"sourceCode":"    *,\n    writable: bool,\n    target: str,\n    order: IndexOrder = \"fortran\",\n) -> np.ndarray[Any, Any]:\n    \"\"\"Convert a DataFrame to a NumPy array for use with Jax or PyTorch.\"\"\"\n    for nm, tp in df.schema.items():\n        if tp == List:\n            msg = f\"cannot convert List column {nm!r} to {target} (use Array dtype instead)\"\n            raise TypeError(msg) from None\n\n    if df.width == 1 and df.schema.dtypes()[0] == Array:\n        arr = df[df.columns[0]].to_numpy(writable=writable)\n    else:\n        arr = df.to_numpy(writable=writable, order=order)\n\n    if arr.dtype == object:\n        msg = f\"cannot convert DataFrame to {target} (mixed type columns result in `object` dtype)\\n{df.schema!r}\"\n        raise TypeError(msg)\n    return arr\n","sourceCodeStart":11,"sourceCodeEnd":31,"githubUrl":"https://github.com/pola-rs/polars/blob/9b5d73fd00236295624374b075d16b1fe6ec6df9/py-polars/src/polars/ml/utilities.py#L11-L31","documentation":"Post-conversion check in frame_to_numpy: after converting the DataFrame to a numpy array the array's dtype came out as `object`, which happens when columns of mixed/incompatible dtypes are concatenated — such arrays cannot be used as Jax/PyTorch tensors. The full schema is included to show which columns caused the object dtype.","triggerScenarios":"Thrown at py-polars/src/polars/ml/utilities.py:29 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Cast or select columns so the frame is homogeneous in dtype before converting to numpy/other targets; mixed types yield object dtype."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"9b5d73fd00236295624374b075d16b1fe6ec6df9","analyzedAt":"2026-08-19T12:15:06.350Z","contentChangedAt":"2026-08-19T12:15:06.350Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}