| 42 | } |
| 43 | |
| 44 | pub(crate) fn dataframe_from_csv_bytes( |
| 45 | bytes: &[u8], |
| 46 | separator: u8, |
| 47 | has_header: bool, |
| 48 | infer_schema_length: Option<usize>, |
| 49 | ) -> anyhow::Result<DataFrame> { |
| 50 | let cursor = std::io::Cursor::new(bytes); |
| 51 | let csv_parse_options = CsvParseOptions::default() |
| 52 | .with_separator(separator) |
| 53 | .with_quote_char(Some(b'"')) |
| 54 | .with_null_values(Some(NullValues::AllColumnsSingle("NA".to_string().into()))); |
| 55 | |
| 56 | let df = CsvReadOptions::default() |
| 57 | .with_has_header(has_header) |
| 58 | .with_infer_schema_length(infer_schema_length) |
| 59 | .with_parse_options(csv_parse_options) |
| 60 | .into_reader_with_file_handle(cursor) |
| 61 | .finish()?; |
| 62 | |
| 63 | Ok(df) |
| 64 | } |