use crate::types::ColumnType;
pub fn is_missing(s: &str) -> bool {
let t = s.trim();
if t.is_empty() {
return true;
}
matches!(
t.to_ascii_lowercase().as_str(),
"na" | "n/a" | "null" | "nan" | "none" | "-" | "?"
)
}
pub fn infer_column(cells: &[String]) -> ColumnType {
let any_non_missing = cells.iter().any(|c| !is_missing(c));
if !any_non_missing {
return ColumnType::Categorical;
}
let all_numeric = cells
.iter()
.all(|c| is_missing(c) || c.trim().parse::<f64>().is_ok());
if all_numeric {
ColumnType::Numeric
} else {
ColumnType::Categorical
}
}
pub fn parse_numeric_column(cells: &[String]) -> Vec<f64> {
cells
.iter()
.map(|c| {
if is_missing(c) {
f64::NAN
} else {
c.trim().parse::<f64>().unwrap_or(f64::NAN)
}
})
.collect()
}