use polars::prelude::*;
use polite::prelude::*;
use tempfile::NamedTempFile;
#[test]
fn test_roundtrip_dataframe() {
let db = NamedTempFile::new().unwrap();
let db_path = db.path().to_str().unwrap();
let df = df! {
"id" => &[1i64, 2, 3],
"name" => &["Alice", "Bob", "Charlie"],
}
.unwrap();
let conn = connect_sqlite(Some(db_path)).unwrap();
from_dataframe(&conn, "people", &df).unwrap();
let df2 = to_dataframe(db_path, "SELECT * FROM people ORDER BY id").unwrap();
assert_eq!(df.shape(), df2.shape());
assert_eq!(
df.column("id")
.unwrap()
.i64()
.unwrap()
.into_no_null_iter()
.collect::<Vec<_>>(),
df2.column("id")
.unwrap()
.i64()
.unwrap()
.into_no_null_iter()
.collect::<Vec<_>>()
);
assert_eq!(
df.column("name")
.unwrap()
.str()
.unwrap()
.into_no_null_iter()
.collect::<Vec<_>>(),
df2.column("name")
.unwrap()
.str()
.unwrap()
.into_no_null_iter()
.collect::<Vec<_>>()
);
}
#[test]
#[ignore] fn test_roundtrip_dataframe_values() {
let db = NamedTempFile::new().unwrap();
let db_path = db.path().to_str().unwrap();
let conn = connect_sqlite(Some(db_path)).unwrap();
let df = df! {
"id" => &[1, 2, 3],
"name" => &["Alice", "Bob", "Charlie"],
}
.unwrap();
from_dataframe(&conn, "people", &df).unwrap();
let df2 = to_dataframe(db_path, "SELECT * FROM people ORDER BY id").unwrap();
assert_eq!(df.shape(), df2.shape());
assert_eq!(
df.column("id")
.unwrap()
.i64()
.unwrap()
.into_no_null_iter()
.collect::<Vec<_>>(),
df2.column("id")
.unwrap()
.i64()
.unwrap()
.into_no_null_iter()
.collect::<Vec<_>>()
);
assert_eq!(
df.column("name")
.unwrap()
.str()
.unwrap()
.into_no_null_iter()
.collect::<Vec<_>>(),
df2.column("name")
.unwrap()
.str()
.unwrap()
.into_no_null_iter()
.collect::<Vec<_>>()
);
}