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

Function select_info_elem_to_indices

src/shared/utils/mod.rs:5–42  ·  view source on GitHub ↗
(
    elem: &SelectInfoElem,
    bound: usize,
)

Source from the content-addressed store, hash-verified

3use polars::prelude::{CsvParseOptions, CsvReadOptions, DataFrame, NullValues, SerReader};
4
5pub(crate) fn select_info_elem_to_indices(
6 elem: &SelectInfoElem,
7 bound: usize,
8) -> anyhow::Result<Vec<usize>> {
9 match elem {
10 SelectInfoElem::Index(indices) => {
11 // For Index, we just need to verify that all indices are within bounds
12 for &idx in indices {
13 if idx >= bound {
14 anyhow::bail!("Index out of bounds: {} >= {}", idx, bound);
15 }
16 }
17 Ok(indices.clone())
18 }
19 SelectInfoElem::Slice(slice) => {
20 let Slice { start, end, step } = *slice;
21 let end = end.unwrap_or(bound as isize);
22
23 // Ensure the slice is within bounds
24 if start as usize >= bound || end as usize > bound {
25 anyhow::bail!(
26 "Slice out of bounds: start={}, end={}, bound={}",
27 start,
28 end,
29 bound
30 );
31 }
32
33 // Generate indices based on the slice
34 let indices: Vec<usize> = (start..end)
35 .step_by(step as usize)
36 .map(|i| i as usize)
37 .collect();
38
39 Ok(indices)
40 }
41 }
42}
43
44pub(crate) fn dataframe_from_csv_bytes(
45 bytes: &[u8],

Calls 1

cloneMethod · 0.80

Tested by

no test coverage detected