fix: handling u64 properly in coeff results

This commit is contained in:
Youngjoon Lee 2024-09-10 07:22:24 +09:00
parent 1e378c7101
commit 27e0850e77
No known key found for this signature in database
GPG Key ID: 167546E2D1712F8C
2 changed files with 16 additions and 8 deletions

View File

@ -71,11 +71,11 @@ fn aggregate(path: &str) {
fn add_stats_columns(df: &mut DataFrame, path: PathBuf, col_prefix: &str) {
let mut schema = Schema::new();
schema.with_column("min".into(), DataType::Float64);
schema.with_column("min".into(), DataType::UInt64);
schema.with_column("median".into(), DataType::Float64);
schema.with_column("mean".into(), DataType::Float64);
schema.with_column("std".into(), DataType::Float64);
schema.with_column("max".into(), DataType::Float64);
schema.with_column("max".into(), DataType::UInt64);
let stats_df = CsvReadOptions::default()
.with_has_header(true)

View File

@ -5,6 +5,13 @@ use std::fs::File;
use walkdir::WalkDir;
fn aggregate(path: &str) {
let mut input_schema = Schema::new();
input_schema.with_column("sender".into(), DataType::UInt64);
input_schema.with_column("receiver".into(), DataType::UInt64);
input_schema.with_column("strong".into(), DataType::UInt64);
input_schema.with_column("casual".into(), DataType::UInt64);
input_schema.with_column("weak".into(), DataType::UInt64);
for entry in WalkDir::new(path)
.into_iter()
.filter_map(|e| e.ok())
@ -12,14 +19,15 @@ fn aggregate(path: &str) {
{
let dir_name = entry.path().file_name().unwrap().to_string_lossy();
if dir_name.starts_with("paramset_") {
let mut strongs = Series::new_empty("", &DataType::Int64);
let mut casuals = Series::new_empty("", &DataType::Int64);
let mut weaks = Series::new_empty("", &DataType::Int64);
let mut strongs = Series::new_empty("", &DataType::UInt64);
let mut casuals = Series::new_empty("", &DataType::UInt64);
let mut weaks = Series::new_empty("", &DataType::UInt64);
let pattern = format!("{}/**/coeffs_*.csv", entry.path().display());
for file in glob(&pattern).unwrap().filter_map(Result::ok) {
let df = CsvReadOptions::default()
.with_has_header(true)
.with_schema(Some(SchemaRef::new(input_schema.clone())))
.try_into_reader_with_file_path(Some(file.clone()))
.unwrap()
.finish()
@ -53,7 +61,7 @@ fn extend_series(series: &mut Series, df: &DataFrame, column: &str) {
.extend(
&df.column(column)
.unwrap()
.i64()
.u64()
.unwrap()
.clone()
.into_series(),
@ -63,11 +71,11 @@ fn extend_series(series: &mut Series, df: &DataFrame, column: &str) {
fn save_stats(aggregated: &Series, outpath: &str) {
let mut df = DataFrame::new(vec![
Series::new("min", &[aggregated.min::<i64>().unwrap()]),
Series::new("min", &[aggregated.min::<u64>().unwrap()]),
Series::new("median", &[aggregated.median().unwrap()]),
Series::new("mean", &[aggregated.mean().unwrap()]),
Series::new("std", &[aggregated.std(1).unwrap()]),
Series::new("max", &[aggregated.max::<i64>().unwrap()]),
Series::new("max", &[aggregated.max::<u64>().unwrap()]),
])
.unwrap();