MCPcopy Create free account
hub / github.com/SingleRust/SingleRust / dataframe_from_csv_bytes

Function dataframe_from_csv_bytes

src/shared/utils/mod.rs:44–64  ·  view source on GitHub ↗
(
    bytes: &[u8],
    separator: u8,
    has_header: bool,
    infer_schema_length: Option<usize>,
)

Source from the content-addressed store, hash-verified

42}
43
44pub(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}

Callers 1

load_resourceFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected