liboxen 0.53.0

Oxen is a fast data version control system, built with machine learning training data in mind. Designed to handle terabytes of data with ease, using a workflow similar to git. Version both structured and unstructured data of any modality: text, images, video, audio, CSV, Parquet, JSONL, model checkpoints, and more. liboxen is the embeddable core library behind the oxen CLI and server, which power fine tuning and inference pipelines for multimodal LLMs, image models, and video models on Oxen.ai.
use polars::{error::PolarsError, frame::DataFrame};
use serde::{Deserialize, Serialize};
use utoipa::ToSchema;

use crate::constants::DIFF_STATUS_COL;

#[derive(Default, Serialize, Deserialize, Debug, Clone, ToSchema)]
pub struct AddRemoveModifyCounts {
    pub added: usize,
    pub removed: usize,
    pub modified: usize,
}

impl AddRemoveModifyCounts {
    pub fn from_diff_df(df: &DataFrame) -> Result<AddRemoveModifyCounts, PolarsError> {
        let added_rows = df
            .column(DIFF_STATUS_COL)?
            .str()?
            .into_iter()
            .filter(|opt| opt.as_ref().map(|s| *s == "added").unwrap_or(false))
            .count();

        let removed_rows = df
            .column(DIFF_STATUS_COL)?
            .str()?
            .into_iter()
            .filter(|opt| opt.as_ref().map(|s| *s == "removed").unwrap_or(false))
            .count();

        let modified_rows = df
            .column(DIFF_STATUS_COL)?
            .str()?
            .into_iter()
            .filter(|opt| opt.as_ref().map(|s| *s == "modified").unwrap_or(false))
            .count();

        Ok(AddRemoveModifyCounts {
            added: added_rows,
            removed: removed_rows,
            modified: modified_rows,
        })
    }
}