#![warn(missing_docs)]
#![warn(clippy::all)]
#![warn(clippy::pedantic)]
#![allow(clippy::module_name_repetitions)]
pub mod csv;
mod delimiter;
mod error;
#[cfg(feature = "excel")]
mod excel;
mod file_type;
mod loader;
mod options;
pub use delimiter::Delimiter;
pub use error::{DataLoadError, Result};
pub use file_type::FileType;
pub use loader::{load_bytes, load_file, DataLoader};
pub use options::LoadOptions;
pub use csv::load_csv_with_fallback;
pub use polars::prelude::DataFrame;
#[cfg(feature = "excel")]
pub use excel::list_sheets;
pub mod prelude {
pub use crate::csv::load_csv_with_fallback;
pub use crate::delimiter::Delimiter;
pub use crate::error::{DataLoadError, Result};
pub use crate::loader::{load_bytes, load_file, DataLoader};
pub use crate::options::LoadOptions;
pub use polars::prelude::DataFrame;
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_prelude_imports() {
use crate::prelude::*;
let _ = DataLoader::new();
let _ = Delimiter::Auto;
let _ = LoadOptions::new();
}
#[test]
fn test_basic_csv_loading() {
let data = b"a,b,c\n1,2,3\n4,5,6";
let df = load_bytes(data, "test.csv").unwrap();
assert_eq!(df.shape(), (2, 3));
assert_eq!(df.get_column_names(), &["a", "b", "c"]);
}
#[test]
fn test_tab_separated() {
let data = b"x\ty\tz\n10\t20\t30";
let df = DataLoader::new()
.load_bytes(data, "test.tsv")
.unwrap();
assert_eq!(df.shape(), (1, 3));
}
#[test]
fn test_semicolon_separated() {
let data = b"col1;col2;col3\na;b;c\nd;e;f";
let df = load_bytes(data, "test.csv").unwrap();
assert_eq!(df.shape(), (2, 3));
}
#[test]
fn test_no_header() {
let data = b"1,2,3\n4,5,6";
let df = DataLoader::new()
.with_header(false)
.load_bytes(data, "test.csv")
.unwrap();
assert_eq!(df.shape(), (2, 3));
}
#[test]
fn test_max_rows() {
let data = b"h1,h2\n1,2\n3,4\n5,6\n7,8\n9,10";
let df = DataLoader::new()
.with_max_rows(Some(2))
.load_bytes(data, "test.csv")
.unwrap();
assert_eq!(df.shape(), (2, 2));
}
#[test]
fn test_unsupported_file_type() {
let result = load_bytes(b"{}", "test.json");
assert!(matches!(result, Err(DataLoadError::UnsupportedFileType(_))));
}
}