mirror of
https://github.com/Magnus167/msyrs.git
synced 2025-08-20 04:20:00 +00:00
fix: improve error messages in check_quantamental_dataframe function
This commit is contained in:
parent
3d2afa01a8
commit
5d2ff3b88d
@ -17,14 +17,15 @@ use std::error::Error;
|
|||||||
pub fn check_quantamental_dataframe(df: &DataFrame) -> Result<(), Box<dyn Error>> {
|
pub fn check_quantamental_dataframe(df: &DataFrame) -> Result<(), Box<dyn Error>> {
|
||||||
let expected_cols = ["real_date", "cid", "xcat"];
|
let expected_cols = ["real_date", "cid", "xcat"];
|
||||||
let expected_dtype = [DataType::Date, DataType::String, DataType::String];
|
let expected_dtype = [DataType::Date, DataType::String, DataType::String];
|
||||||
|
let err = "Quantamental DataFrame must have at least 4 columns: 'real_date', 'cid', 'xcat' and one or more metrics.";
|
||||||
for (col, dtype) in expected_cols.iter().zip(expected_dtype.iter()) {
|
for (col, dtype) in expected_cols.iter().zip(expected_dtype.iter()) {
|
||||||
let col = df.column(col);
|
let col = df.column(col);
|
||||||
if col.is_err() {
|
if col.is_err() {
|
||||||
return Err(format!("Column {:?} not found", col).into());
|
return Err(format!("{} Column {:?} not found", err, col).into());
|
||||||
}
|
}
|
||||||
let col = col?;
|
let col = col?;
|
||||||
if col.dtype() != dtype {
|
if col.dtype() != dtype {
|
||||||
return Err(format!("Column {:?} has wrong dtype", col).into());
|
return Err(format!("{} Column {:?} has wrong dtype", err, col).into());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user