refactor: move files

This commit is contained in:
Elijah McMorris 2024-06-15 02:31:22 +00:00
parent 4f262dc477
commit 4283264b0e
Signed by: NexVeridian
SSH key fingerprint: SHA256:bsA1SKZxuEcEVHAy3gY1HUeM5ykRJl0U0kQHQn0hMg8
6 changed files with 178 additions and 159 deletions

51
src/util/df.rs Normal file
View file

@ -0,0 +1,51 @@
use polars::frame::DataFrame;
use polars::prelude::{IntoLazy, LazyFrame};
use anyhow::Error;
#[derive(Clone)]
pub enum DF {
LazyFrame(LazyFrame),
DataFrame(DataFrame),
}
impl From<LazyFrame> for DF {
fn from(lf: LazyFrame) -> Self {
DF::LazyFrame(lf)
}
}
impl From<DataFrame> for DF {
fn from(df: DataFrame) -> Self {
DF::DataFrame(df)
}
}
impl DF {
pub fn collect(self) -> anyhow::Result<DataFrame, Error> {
match self {
DF::LazyFrame(x) => Ok(x.collect()?),
DF::DataFrame(x) => Ok(x),
}
}
pub fn lazy(self) -> LazyFrame {
match self {
DF::LazyFrame(x) => x,
DF::DataFrame(x) => x.lazy(),
}
}
}
#[allow(clippy::upper_case_acronyms)]
pub trait DFS {
fn lazy(self) -> Vec<LazyFrame>;
fn collect(self) -> Vec<DataFrame>;
}
impl DFS for Vec<DF> {
fn lazy(self) -> Vec<LazyFrame> {
self.into_iter().map(|df| df.lazy()).collect()
}
fn collect(self) -> Vec<DataFrame> {
self.into_iter().map(|df| df.collect().unwrap()).collect()
}
}