Skip to content

Commit

Permalink
refactor: Move path logic to from utils to path_utils in polars-io (
Browse files Browse the repository at this point in the history
  • Loading branch information
nameexhaustion authored Jul 15, 2024
1 parent 83b7bef commit d76609a
Show file tree
Hide file tree
Showing 19 changed files with 23 additions and 22 deletions.
4 changes: 2 additions & 2 deletions crates/polars-io/src/cloud/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ use url::Url;
#[cfg(feature = "file_cache")]
use crate::file_cache::get_env_file_cache_ttl;
#[cfg(feature = "aws")]
use crate::pl_async::with_concurrency_budget;
use crate::path_utils::resolve_homedir;
#[cfg(feature = "aws")]
use crate::utils::resolve_homedir;
use crate::pl_async::with_concurrency_budget;

#[cfg(feature = "aws")]
static BUCKET_REGION: Lazy<std::sync::Mutex<FastFixedCache<SmartString, SmartString>>> =
Expand Down
2 changes: 1 addition & 1 deletion crates/polars-io/src/csv/read/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use super::buffer::Buffer;
use super::options::{CommentPrefix, NullValuesCompiled};
use super::splitfields::SplitFields;
use super::utils::get_file_chunks;
use crate::prelude::is_cloud_url;
use crate::path_utils::is_cloud_url;
use crate::utils::get_reader_bytes;

/// Read the number of rows without parsing columns
Expand Down
3 changes: 2 additions & 1 deletion crates/polars-io/src/csv/read/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ use super::read_impl::batched::to_batched_owned;
use super::read_impl::CoreReader;
use super::{infer_file_schema, BatchedCsvReader, OwnedBatchedCsvReader};
use crate::mmap::MmapBytesReader;
use crate::path_utils::resolve_homedir;
use crate::predicates::PhysicalIoExpr;
use crate::shared::SerReader;
use crate::utils::{get_reader_bytes, resolve_homedir};
use crate::utils::get_reader_bytes;

/// Create a new DataFrame by reading a csv file.
///
Expand Down
5 changes: 2 additions & 3 deletions crates/polars-io/src/file_cache/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ use super::entry::{FileCacheEntry, DATA_PREFIX, METADATA_PREFIX};
use super::eviction::EvictionManager;
use super::file_fetcher::FileFetcher;
use super::utils::FILE_CACHE_PREFIX;
use crate::prelude::is_cloud_url;
use crate::utils::ensure_directory_init;
use crate::path_utils::{ensure_directory_init, is_cloud_url};

pub static FILE_CACHE: Lazy<FileCache> = Lazy::new(|| {
let prefix = FILE_CACHE_PREFIX.as_ref();
Expand Down Expand Up @@ -101,7 +100,7 @@ impl FileCache {
#[cfg(debug_assertions)]
{
// Local paths must be absolute or else the cache would be wrong.
if !crate::utils::is_cloud_url(uri.as_ref()) {
if !crate::path_utils::is_cloud_url(uri.as_ref()) {
let path = Path::new(uri.as_ref());
assert_eq!(path, std::fs::canonicalize(path).unwrap().as_path());
}
Expand Down
3 changes: 1 addition & 2 deletions crates/polars-io/src/file_cache/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ use super::file_fetcher::{CloudFileFetcher, LocalFileFetcher};
use crate::cloud::{
build_object_store, object_path_from_string, CloudLocation, CloudOptions, PolarsObjectStore,
};
use crate::path_utils::{ensure_directory_init, is_cloud_url, POLARS_TEMP_DIR_BASE_PATH};
use crate::pl_async;
use crate::prelude::{is_cloud_url, POLARS_TEMP_DIR_BASE_PATH};
use crate::utils::ensure_directory_init;

pub static FILE_CACHE_PREFIX: Lazy<Box<Path>> = Lazy::new(|| {
let path = POLARS_TEMP_DIR_BASE_PATH
Expand Down
2 changes: 2 additions & 0 deletions crates/polars-io/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ mod options;
pub mod parquet;
#[cfg(feature = "parquet")]
pub mod partition;
pub mod path_utils;
#[cfg(feature = "async")]
pub mod pl_async;
pub mod predicates;
Expand All @@ -31,6 +32,7 @@ pub mod utils;
#[cfg(feature = "cloud")]
pub use cloud::glob as async_glob;
pub use options::*;
pub use path_utils::*;
pub use shared::*;

pub mod hive;
2 changes: 1 addition & 1 deletion crates/polars-io/src/ndjson/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ where
impl<'a> JsonLineReader<'a, File> {
/// This is the recommended way to create a json reader as this allows for fastest parsing.
pub fn from_path<P: Into<PathBuf>>(path: P) -> PolarsResult<Self> {
let path = resolve_homedir(&path.into());
let path = crate::resolve_homedir(&path.into());
let f = polars_utils::open_file(&path)?;
Ok(Self::new(f).with_path(Some(path)))
}
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions crates/polars-io/src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ pub use crate::ndjson::core::*;
pub use crate::parquet::{metadata::*, read::*, write::*};
#[cfg(feature = "parquet")]
pub use crate::partition::write_partitioned_dataset;
pub use crate::path_utils::*;
pub use crate::shared::{SerReader, SerWriter};
pub use crate::utils::*;
2 changes: 0 additions & 2 deletions crates/polars-io/src/utils/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
mod other;
mod path;

pub use other::*;
pub use path::*;
3 changes: 2 additions & 1 deletion crates/polars-lazy/src/scan/csv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ use polars_io::cloud::CloudOptions;
use polars_io::csv::read::{
infer_file_schema, CommentPrefix, CsvEncoding, CsvParseOptions, CsvReadOptions, NullValues,
};
use polars_io::utils::{expand_paths, get_reader_bytes};
use polars_io::path_utils::expand_paths;
use polars_io::utils::get_reader_bytes;
use polars_io::RowIndex;

use crate::prelude::*;
Expand Down
2 changes: 1 addition & 1 deletion crates/polars-mem-engine/src/executors/scan/ipc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use hive::HivePartitions;
use polars_core::config;
use polars_core::utils::accumulate_dataframes_vertical;
use polars_io::cloud::CloudOptions;
use polars_io::path_utils::is_cloud_url;
use polars_io::predicates::apply_predicate;
use polars_io::utils::is_cloud_url;
use rayon::prelude::*;

use super::*;
Expand Down
2 changes: 1 addition & 1 deletion crates/polars-mem-engine/src/executors/scan/parquet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use polars_core::config::{get_file_prefetch_size, verbose};
use polars_core::utils::accumulate_dataframes_vertical;
use polars_io::cloud::CloudOptions;
use polars_io::parquet::metadata::FileMetaDataRef;
use polars_io::utils::is_cloud_url;
use polars_io::path_utils::is_cloud_url;
use polars_io::RowIndex;

use super::*;
Expand Down
2 changes: 1 addition & 1 deletion crates/polars-pipe/src/executors/sources/csv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::path::PathBuf;

use polars_core::{config, POOL};
use polars_io::csv::read::{BatchedCsvReader, CsvReadOptions, CsvReader};
use polars_io::utils::is_cloud_url;
use polars_io::path_utils::is_cloud_url;
use polars_plan::global::_set_n_rows_for_scan;
use polars_plan::prelude::FileScanOptions;
use polars_utils::iter::EnumerateIdxTrait;
Expand Down
2 changes: 1 addition & 1 deletion crates/polars-pipe/src/executors/sources/parquet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ use polars_core::POOL;
use polars_io::cloud::CloudOptions;
use polars_io::parquet::metadata::FileMetaDataRef;
use polars_io::parquet::read::{BatchedParquetReader, ParquetOptions, ParquetReader};
use polars_io::path_utils::is_cloud_url;
use polars_io::pl_async::get_runtime;
use polars_io::predicates::PhysicalIoExpr;
use polars_io::prelude::materialize_projection;
#[cfg(feature = "async")]
use polars_io::prelude::ParquetAsyncReader;
use polars_io::utils::is_cloud_url;
use polars_io::SerReader;
use polars_plan::plans::FileInfo;
use polars_plan::prelude::hive::HivePartitions;
Expand Down
4 changes: 2 additions & 2 deletions crates/polars-plan/src/plans/conversion/dsl_to_ir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ use hive::{hive_partitions_from_paths, HivePartitions};
#[cfg(any(feature = "ipc", feature = "parquet"))]
use polars_io::cloud::CloudOptions;
#[cfg(any(feature = "csv", feature = "json"))]
use polars_io::utils::expand_paths;
use polars_io::path_utils::expand_paths;
#[cfg(any(feature = "ipc", feature = "parquet"))]
use polars_io::utils::{expand_paths_hive, expanded_from_single_directory};
use polars_io::path_utils::{expand_paths_hive, expanded_from_single_directory};

use super::stack_opt::ConversionOptimizer;
use super::*;
Expand Down
2 changes: 1 addition & 1 deletion crates/polars-plan/src/plans/conversion/scans.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use std::path::PathBuf;

use either::Either;
use polars_io::path_utils::is_cloud_url;
#[cfg(feature = "cloud")]
use polars_io::pl_async::get_runtime;
use polars_io::prelude::*;
use polars_io::utils::is_cloud_url;
use polars_io::RowIndex;

use super::*;
Expand Down
2 changes: 1 addition & 1 deletion crates/polars-plan/src/plans/functions/count.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use polars_io::parquet::read::ParquetReader;
#[cfg(all(feature = "parquet", feature = "async"))]
use polars_io::pl_async::{get_runtime, with_concurrency_budget};
#[cfg(any(feature = "parquet", feature = "ipc"))]
use polars_io::{utils::is_cloud_url, SerReader};
use polars_io::{path_utils::is_cloud_url, SerReader};

use super::*;

Expand Down
2 changes: 1 addition & 1 deletion crates/polars-plan/src/plans/hive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ pub fn hive_partitions_from_paths(
/// Determine the path separator for identifying Hive partitions.
#[cfg(target_os = "windows")]
fn separator(url: &Path) -> char {
if polars_io::utils::is_cloud_url(url) {
if polars_io::path_utils::is_cloud_url(url) {
'/'
} else {
'\\'
Expand Down

0 comments on commit d76609a

Please sign in to comment.