use polars::frame::DataFrame; use polars::prelude::{IntoLazy, LazyFrame}; use anyhow::Error; #[derive(Clone)] pub enum DF { LazyFrame(LazyFrame), DataFrame(DataFrame), } impl From for DF { fn from(lf: LazyFrame) -> Self { DF::LazyFrame(lf) } } impl From for DF { fn from(df: DataFrame) -> Self { DF::DataFrame(df) } } impl DF { pub fn collect(self) -> anyhow::Result { 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; fn collect(self) -> Vec; } impl DFS for Vec { fn lazy(self) -> Vec { self.into_iter().map(|df| df.lazy()).collect() } fn collect(self) -> Vec { self.into_iter().map(|df| df.collect().unwrap()).collect() } }