mirror of
https://github.com/NexVeridian/ark-invest-api-rust-data.git
synced 2025-09-02 09:59:12 +00:00
refactor: move files
This commit is contained in:
parent
4f262dc477
commit
4283264b0e
6 changed files with 178 additions and 159 deletions
51
src/util/df.rs
Normal file
51
src/util/df.rs
Normal 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()
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue