From 0b1f5ec9569dcc04c765a45c4ee5bc1eceea45d6 Mon Sep 17 00:00:00 2001 From: Marc Garcia Date: Mon, 24 Jun 2024 14:51:16 +0400 Subject: [PATCH] feat(rust): Use AsRef instead of PathBuf in sink_ methods (#17150) --- crates/polars-lazy/src/frame/mod.rs | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/crates/polars-lazy/src/frame/mod.rs b/crates/polars-lazy/src/frame/mod.rs index c438d169b421..e9ccc4a6b4b4 100644 --- a/crates/polars-lazy/src/frame/mod.rs +++ b/crates/polars-lazy/src/frame/mod.rs @@ -15,7 +15,7 @@ pub mod pivot; feature = "csv", feature = "json" ))] -use std::path::PathBuf; +use std::path::Path; use std::sync::{Arc, Mutex}; pub use anonymous_scan::*; @@ -752,10 +752,14 @@ impl LazyFrame { /// into memory. This methods will return an error if the query cannot be completely done in a /// streaming fashion. #[cfg(feature = "parquet")] - pub fn sink_parquet(self, path: PathBuf, options: ParquetWriteOptions) -> PolarsResult<()> { + pub fn sink_parquet( + self, + path: impl AsRef, + options: ParquetWriteOptions, + ) -> PolarsResult<()> { self.sink( SinkType::File { - path: Arc::new(path), + path: Arc::new(path.as_ref().to_path_buf()), file_type: FileType::Parquet(options), }, "collect().write_parquet()", @@ -787,10 +791,10 @@ impl LazyFrame { /// into memory. This methods will return an error if the query cannot be completely done in a /// streaming fashion. #[cfg(feature = "ipc")] - pub fn sink_ipc(self, path: PathBuf, options: IpcWriterOptions) -> PolarsResult<()> { + pub fn sink_ipc(self, path: impl AsRef, options: IpcWriterOptions) -> PolarsResult<()> { self.sink( SinkType::File { - path: Arc::new(path), + path: Arc::new(path.as_ref().to_path_buf()), file_type: FileType::Ipc(options), }, "collect().write_ipc()", @@ -832,10 +836,10 @@ impl LazyFrame { /// into memory. This methods will return an error if the query cannot be completely done in a /// streaming fashion. #[cfg(feature = "csv")] - pub fn sink_csv(self, path: PathBuf, options: CsvWriterOptions) -> PolarsResult<()> { + pub fn sink_csv(self, path: impl AsRef, options: CsvWriterOptions) -> PolarsResult<()> { self.sink( SinkType::File { - path: Arc::new(path), + path: Arc::new(path.as_ref().to_path_buf()), file_type: FileType::Csv(options), }, "collect().write_csv()", @@ -846,10 +850,10 @@ impl LazyFrame { /// into memory. This methods will return an error if the query cannot be completely done in a /// streaming fashion. #[cfg(feature = "json")] - pub fn sink_json(self, path: PathBuf, options: JsonWriterOptions) -> PolarsResult<()> { + pub fn sink_json(self, path: impl AsRef, options: JsonWriterOptions) -> PolarsResult<()> { self.sink( SinkType::File { - path: Arc::new(path), + path: Arc::new(path.as_ref().to_path_buf()), file_type: FileType::Json(options), }, "collect().write_ndjson()` or `collect().write_json()",