Skip to content

Commit

Permalink
Update polars from 0.38 to 0.40 (#785)
Browse files Browse the repository at this point in the history
Signed-off-by: Nico Wagner <[email protected]>
  • Loading branch information
nwagner84 authored May 29, 2024
1 parent 1fc4682 commit 3efe646
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ clap = "4.5"
clap_complete = "4.5"
csv = "1.3"
flate2 = "1.0"
polars = { version = "0.38", features = ["ipc", "decompress", "performant"] }
polars = { version = "0.40", features = ["ipc", "decompress", "performant"] }
quickcheck = "1.0"
rand = "0.8"
regex = "1.10"
Expand Down
43 changes: 22 additions & 21 deletions crates/pica-toolkit/src/filter_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,35 +93,36 @@ impl FilterList {
) -> Result<DataFrame, FilterListError> {
let extension = path.extension().and_then(OsStr::to_str);
let path_str = path.to_str().unwrap_or_default();
let path = path.to_owned();

let options = CsvReadOptions::default()
.with_has_header(true)
.with_infer_schema_length(Some(0));

match extension {
Some("ipc" | "arrow" | "feather") => {
Ok(IpcReader::new(File::open(path)?)
.memory_mapped(false)
.memory_mapped(None)
.finish()?)
}
Some("csv") => Ok(CsvReader::from_path(path)?
.infer_schema(Some(0))
.has_header(true)
Some("csv") => Ok(options
.try_into_reader_with_file_path(Some(path))?
.finish()?),
Some("gz") if path_str.ends_with(".csv.gz") => {
Ok(CsvReader::from_path(path)?
.infer_schema(Some(0))
.has_header(true)
.finish()?)
}
Some("tsv") => Ok(CsvReader::from_path(path)?
.with_separator(b'\t')
.has_header(true)
.infer_schema(Some(0))
Some("gz") if path_str.ends_with(".csv.gz") => Ok(options
.try_into_reader_with_file_path(Some(path))?
.finish()?),
Some("tsv") => Ok(options
.with_parse_options(
CsvParseOptions::default().with_separator(b'\t'),
)
.try_into_reader_with_file_path(Some(path))?
.finish()?),
Some("gz") if path_str.ends_with(".tsv.gz") => Ok(options
.with_parse_options(
CsvParseOptions::default().with_separator(b'\t'),
)
.try_into_reader_with_file_path(Some(path))?
.finish()?),
Some("gz") if path_str.ends_with(".tsv.gz") => {
Ok(CsvReader::from_path(path)?
.with_separator(b'\t')
.infer_schema(Some(0))
.has_header(true)
.finish()?)
}
_ => {
Err(FilterListError::InvalidFileFormat(path_str.into()))
}
Expand Down

0 comments on commit 3efe646

Please sign in to comment.