dt-cli-tools

CLI tools for viewing, filtering, and comparing tabular data files
Log | Files | Refs | README | LICENSE

writer.rs (692B)


      1 use anyhow::{bail, Result};
      2 use polars::prelude::*;
      3 use std::path::Path;
      4 
      5 use crate::format::Format;
      6 use crate::writers;
      7 
      8 /// Write a DataFrame to a file or stdout, dispatching to the appropriate writer.
      9 pub fn write_file(df: &mut DataFrame, path: Option<&Path>, format: Format) -> Result<()> {
     10     match format {
     11         Format::Csv | Format::Tsv => writers::csv::write(df, path, format),
     12         Format::Parquet => writers::parquet::write(df, path),
     13         Format::Arrow => writers::arrow::write(df, path),
     14         Format::Json | Format::Ndjson => writers::json::write(df, path, format),
     15         Format::Excel => bail!("writing Excel format is not supported; use csv or parquet"),
     16     }
     17 }