Skip to content

Commit

Permalink
feat: Support homedir expansion in lazy/scan read functions
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-beedie committed Jun 11, 2024
1 parent 13d68ae commit d236a44
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 6 deletions.
11 changes: 9 additions & 2 deletions crates/polars-lazy/src/scan/csv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use polars_io::cloud::CloudOptions;
use polars_io::csv::read::{
infer_file_schema, CommentPrefix, CsvEncoding, CsvParseOptions, CsvReadOptions, NullValues,
};
use polars_io::prelude::resolve_homedir;
use polars_io::utils::get_reader_bytes;
use polars_io::RowIndex;

Expand Down Expand Up @@ -35,7 +36,7 @@ impl LazyCsvReader {

pub fn new(path: impl AsRef<Path>) -> Self {
LazyCsvReader {
path: path.as_ref().to_owned(),
path: resolve_homedir(path.as_ref()),
paths: Arc::new([]),
glob: true,
cache: true,
Expand Down Expand Up @@ -305,11 +306,17 @@ impl LazyFileListReader for LazyCsvReader {
}

fn with_path(mut self, path: PathBuf) -> Self {
self.path = path;
self.path = resolve_homedir(&path);
self
}

fn with_paths(mut self, paths: Arc<[PathBuf]>) -> Self {
let paths = paths
.iter()
.map(|p| resolve_homedir(p))
.collect::<Vec<_>>()
.into();

self.paths = paths;
self
}
Expand Down
11 changes: 9 additions & 2 deletions crates/polars-lazy/src/scan/ipc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::path::{Path, PathBuf};
use polars_core::prelude::*;
use polars_io::cloud::CloudOptions;
use polars_io::ipc::IpcScanOptions;
use polars_io::utils::resolve_homedir;
use polars_io::RowIndex;

use crate::prelude::*;
Expand Down Expand Up @@ -41,7 +42,7 @@ impl LazyIpcReader {
fn new(path: PathBuf, args: ScanArgsIpc) -> Self {
Self {
args,
path,
path: resolve_homedir(&path),
paths: Arc::new([]),
}
}
Expand Down Expand Up @@ -96,11 +97,17 @@ impl LazyFileListReader for LazyIpcReader {
}

fn with_path(mut self, path: PathBuf) -> Self {
self.path = path;
self.path = resolve_homedir(&path);
self
}

fn with_paths(mut self, paths: Arc<[PathBuf]>) -> Self {
let paths = paths
.iter()
.map(|p| resolve_homedir(p))
.collect::<Vec<_>>()
.into();

self.paths = paths;
self
}
Expand Down
9 changes: 8 additions & 1 deletion crates/polars-lazy/src/scan/ndjson.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::path::{Path, PathBuf};
use std::sync::RwLock;

use polars_core::prelude::*;
use polars_io::utils::resolve_homedir;
use polars_io::RowIndex;

use super::*;
Expand Down Expand Up @@ -114,11 +115,17 @@ impl LazyFileListReader for LazyJsonLineReader {
}

fn with_path(mut self, path: PathBuf) -> Self {
self.path = path;
self.path = resolve_homedir(&path);
self
}

fn with_paths(mut self, paths: Arc<[PathBuf]>) -> Self {
let paths = paths
.iter()
.map(|p| resolve_homedir(p))
.collect::<Vec<_>>()
.into();

self.paths = paths;
self
}
Expand Down
9 changes: 8 additions & 1 deletion crates/polars-lazy/src/scan/parquet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::path::{Path, PathBuf};
use polars_core::prelude::*;
use polars_io::cloud::CloudOptions;
use polars_io::parquet::read::ParallelStrategy;
use polars_io::prelude::resolve_homedir;
use polars_io::{HiveOptions, RowIndex};

use crate::prelude::*;
Expand Down Expand Up @@ -112,11 +113,17 @@ impl LazyFileListReader for LazyParquetReader {
}

fn with_path(mut self, path: PathBuf) -> Self {
self.path = path;
self.path = resolve_homedir(&path);
self
}

fn with_paths(mut self, paths: Arc<[PathBuf]>) -> Self {
let paths = paths
.iter()
.map(|p| resolve_homedir(p))
.collect::<Vec<_>>()
.into();

self.paths = paths;
self
}
Expand Down

0 comments on commit d236a44

Please sign in to comment.