{"record":{"id":"47dc7a96b8dedbe1","repo":"pola-rs/polars","slug":"could-not-read-from-input","errorCode":null,"errorMessage":"could not read from input","messagePattern":"could not read from input","errorType":"exception","errorClass":"io::Error","httpStatus":null,"severity":"error","filePath":"crates/polars-python/src/file.rs","lineNumber":187,"sourceCode":"    fn read(&mut self, mut buf: &mut [u8]) -> Result<usize, io::Error> {\n        Python::attach(|py| {\n            let bytes = self\n                .inner\n                .call_method(py, \"read\", (buf.len(),), None)\n                .map_err(pyerr_to_io_err)?;\n\n            let opt_bytes = bytes.cast_bound::<PyBytes>(py);\n\n            if let Ok(bytes) = opt_bytes {\n                buf.write_all(bytes.as_bytes())?;\n\n                bytes.len().map_err(pyerr_to_io_err)\n            } else if let Ok(s) = bytes.cast_bound::<PyString>(py) {\n                let s = s.to_cow().map_err(pyerr_to_io_err)?;\n                buf.write_all(s.as_bytes())?;\n                Ok(s.len())\n            } else {\n                Err(io::Error::new(\n                    ErrorKind::InvalidInput,\n                    polars_err!(InvalidOperation: \"could not read from input\"),\n                ))\n            }\n        })\n    }\n}\n\nimpl Write for PyFileLikeObject {\n    fn write(&mut self, buf: &[u8]) -> Result<usize, io::Error> {\n        // Note on the .extract() method:\n        // In case of a PyString object, it returns the number of chars,\n        // so we need to take extra steps if the underlying string is not all ASCII.\n        // In case of a ByBytes object, it returns the number of bytes.\n        let expects_str = self.expects_str;\n        let expects_str_and_is_ascii = expects_str && buf.is_ascii();\n\n        Python::attach(|py| {","sourceCodeStart":169,"sourceCodeEnd":205,"githubUrl":"https://github.com/pola-rs/polars/blob/5d8ebabf11caea54a5c29178a64a058762f49766/crates/polars-python/src/file.rs#L169-L205","documentation":"Error-mapping marker in the Read impl for Python file-like objects: a bounded `read(n)` call on the wrapped Python object raised an exception (converted via pyerr_to_io_err) or its string result failed UTF-8 conversion, so the underlying Python read raised while streaming data into Rust.","triggerScenarios":"This panic/expect fires when execution reaches an unguarded state described by: \"could not read from input\". Typical triggers: unsupported dtype or feature-gated code path reached at runtime, invalid user input or environment variable value, calling API methods in the wrong order or on mismatched types, or data (lengths, offsets, ranges) violating the function's preconditions.","commonSituations":"Encountered when input data or configuration does not meet the preconditions of the throwing code path (\"could not read from input\"). Common cases: missing Cargo feature flags, mismatched dtypes/lengths between arrays or series, out-of-range temporal values, malformed environment variables, or operations on unsupported/complex nested types.","solutions":["Reading from the input failed; check the file-like object is open, readable, and not at EOF unexpectedly.","Check the underlying I/O error of the Python object."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"5d8ebabf11caea54a5c29178a64a058762f49766","analyzedAt":"2026-08-19T12:15:06.350Z","contentChangedAt":"2026-08-19T12:15:06.350Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}