Skip to main content

alopex_dataframe/ops/
mod.rs

1//! Operation-specific types and helpers for P1 DataFrame features.
2
3pub mod join;
4pub mod nulls;
5pub mod sort;
6pub mod unique;
7
8/// Supported join types for `DataFrame::join`.
9#[derive(Debug, Clone, Copy, PartialEq, Eq)]
10pub enum JoinType {
11    Inner,
12    Left,
13    Right,
14    Full,
15    Semi,
16    Anti,
17}
18
19/// Join key specification.
20#[derive(Debug, Clone, PartialEq, Eq)]
21pub enum JoinKeys {
22    /// Same column names on both sides.
23    On(Vec<String>),
24    /// Different column names for each side.
25    LeftRight {
26        left_on: Vec<String>,
27        right_on: Vec<String>,
28    },
29}
30
31impl From<Vec<String>> for JoinKeys {
32    fn from(cols: Vec<String>) -> Self {
33        JoinKeys::On(cols)
34    }
35}
36
37impl From<(Vec<String>, Vec<String>)> for JoinKeys {
38    fn from((left_on, right_on): (Vec<String>, Vec<String>)) -> Self {
39        JoinKeys::LeftRight { left_on, right_on }
40    }
41}
42
43/// Sort configuration for `DataFrame::sort`.
44#[derive(Debug, Clone, PartialEq, Eq)]
45pub struct SortOptions {
46    pub by: Vec<String>,
47    pub descending: Vec<bool>,
48    pub nulls_last: bool,
49    pub stable: bool,
50}
51
52/// Strategies for `fill_null` operations.
53#[derive(Debug, Clone, Copy, PartialEq, Eq)]
54pub enum FillNullStrategy {
55    Forward,
56    Backward,
57    Min,
58    Max,
59    Mean,
60    Zero,
61    One,
62}
63
64/// Fill-null specification (scalar value or strategy).
65#[derive(Debug, Clone, PartialEq)]
66pub enum FillNull {
67    Value(crate::expr::Scalar),
68    Strategy(FillNullStrategy),
69}
70
71impl From<crate::expr::Scalar> for FillNull {
72    fn from(value: crate::expr::Scalar) -> Self {
73        FillNull::Value(value)
74    }
75}
76
77impl From<FillNullStrategy> for FillNull {
78    fn from(strategy: FillNullStrategy) -> Self {
79        FillNull::Strategy(strategy)
80    }
81}
82
83impl From<i64> for FillNull {
84    fn from(value: i64) -> Self {
85        FillNull::Value(value.into())
86    }
87}
88
89impl From<f64> for FillNull {
90    fn from(value: f64) -> Self {
91        FillNull::Value(value.into())
92    }
93}
94
95impl From<bool> for FillNull {
96    fn from(value: bool) -> Self {
97        FillNull::Value(value.into())
98    }
99}
100
101impl From<String> for FillNull {
102    fn from(value: String) -> Self {
103        FillNull::Value(value.into())
104    }
105}
106
107impl From<&str> for FillNull {
108    fn from(value: &str) -> Self {
109        FillNull::Value(value.into())
110    }
111}