Skip to content

Commit

Permalink
rust tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Jan 18, 2024
1 parent 4c0c708 commit 71ce6d4
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
4 changes: 2 additions & 2 deletions crates/polars-core/src/datatypes/any_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1194,8 +1194,8 @@ mod test {
),
(ArrowDataType::LargeUtf8, DataType::String),
(ArrowDataType::Utf8, DataType::String),
(ArrowDataType::LargeBinary, DataType::BinaryOffset),
(ArrowDataType::Binary, DataType::BinaryOffset),
(ArrowDataType::LargeBinary, DataType::Binary),
(ArrowDataType::Binary, DataType::Binary),
(
ArrowDataType::Time64(ArrowTimeUnit::Nanosecond),
DataType::Time,
Expand Down
2 changes: 1 addition & 1 deletion crates/polars-io/src/csv/read_impl/batched_mmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ impl<'a> CoreReader<'a> {
eol_char: self.eol_char,
};

let projection = self.get_projection();
let projection = self.get_projection()?;

// RAII structure that will ensure we maintain a global stringcache
#[cfg(feature = "dtype-categorical")]
Expand Down
2 changes: 1 addition & 1 deletion crates/polars-io/src/csv/read_impl/batched_read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ impl<'a> CoreReader<'a> {
4096,
);

let projection = self.get_projection();
let projection = self.get_projection()?;

// RAII structure that will ensure we maintain a global stringcache
#[cfg(feature = "dtype-categorical")]
Expand Down
11 changes: 7 additions & 4 deletions crates/polars-io/src/csv/read_impl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -436,16 +436,19 @@ impl<'a> CoreReader<'a> {
remaining_bytes,
))
}
fn get_projection(&mut self) -> Vec<usize> {
fn get_projection(&mut self) -> PolarsResult<Vec<usize>> {
// we also need to sort the projection to have predictable output.
// the `parse_lines` function expects this.
self.projection
.take()
.map(|mut v| {
v.sort_unstable();
v
if let Some(idx) = v.last() {
polars_ensure!(*idx < self.schema.len(), OutOfBounds: "projection index: {} is out of bounds for csv schema with length: {}", idx, self.schema.len())
}
Ok(v)
})
.unwrap_or_else(|| (0..self.schema.len()).collect())
.unwrap_or_else(|| Ok((0..self.schema.len()).collect()))
}

fn parse_csv(
Expand All @@ -457,7 +460,7 @@ impl<'a> CoreReader<'a> {
let logging = verbose();
let (file_chunks, chunk_size, total_rows, starting_point_offset, bytes, remaining_bytes) =
self.determine_file_chunks_and_statistics(&mut n_threads, bytes, logging)?;
let projection = self.get_projection();
let projection = self.get_projection()?;

// An empty file with a schema should return an empty DataFrame with that schema
if bytes.is_empty() {
Expand Down

0 comments on commit 71ce6d4

Please sign in to comment.