Skip to content

Commit

Permalink
Updated hashbrown dep based on pola-rs/polars#19076 (comment)
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewalltop committed Oct 9, 2024
1 parent 1551b4b commit c1a98ea
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 38 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ edition = "2021"
[dependencies]
plotlars = "0.5.0"
evcxr = "0.17.0"
hashbrown = "0.15.0"
hashbrown = { version = "0.14", features = ["rayon", "ahash", "serde", "raw"] }
linfa = "0.7.0"
polars = { version = "0.42.0", features = [
"lazy",
Expand Down
2 changes: 2 additions & 0 deletions src/experiments/comorbidity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ use frames::hyperaktiv::*;
use crate::frames;

pub fn comorbidity_of_anxiety_or_mood_disorder() {
// TODO: This belongs in frames - the graphical element can be exposed here, however.

let dataset = load_patient_info(false)
.filter(
col("BIPOLAR")
Expand Down
4 changes: 3 additions & 1 deletion src/frames/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
pub mod hyperaktiv;

/// TODO: This module should stay internal
pub mod hyperaktiv;
pub mod patient_info;
pub mod subtypes;

Expand Down
40 changes: 6 additions & 34 deletions src/frames/patient_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,7 @@
use polars::prelude::*;
use crate::traits::patient_info_ext::{GenderAndADHDTypeFilter, SelectPatientInfoColumns};

/// Returns all patients who have ADHD-PH
pub fn patient_info_has_adhd_hyperactive() -> DataFrame {
load_patient_info(false)
.filter(
col("ADHD").eq(1).and(col("ADD").eq(0))
)
.apply_gender_age_adhd_type_translation()
.select_patient_info_columns()
.collect()
.unwrap()
}

/// Returns all patients who have ADHD-PI
pub fn patient_info_has_adhd_innattentive() -> DataFrame {
load_patient_info(false)
.filter(
col("ADHD").eq(0).and(col("ADD").eq(1))
)
.apply_gender_age_adhd_type_translation()
.select_patient_info_columns()
.collect()
.unwrap()
}

/// Returns all patients who have ADHD-C
pub fn patient_info_has_adhd_combined() -> DataFrame {
load_patient_info(false)
.filter(
col("ADHD").eq(1).and(col("ADD").eq(1))
)
.apply_gender_age_adhd_type_translation()
.select_patient_info_columns()
.collect()
.unwrap()
}

/// Returns all patients who have Bipolar Disorder
pub fn patient_info_has_bipolar_disorder() -> DataFrame {
Expand Down Expand Up @@ -137,4 +103,10 @@ pub fn patient_info_patient_does_not_take_medication() -> DataFrame {
.select_patient_info_columns()
.collect()
.unwrap()
}

#[cfg(test)]
mod test {


}
69 changes: 67 additions & 2 deletions src/frames/subtypes.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use polars::frame::DataFrame;
use polars::prelude::{col};
use crate::frames::hyperaktiv::load_patient_info;
use crate::traits::patient_info_ext::GenderAndADHDTypeFilter;
use crate::traits::patient_info_ext::{GenderAndADHDTypeFilter, SelectPatientInfoColumns};


/// Returns ADHD subtypes, gender, and age ranges of patients.
Expand Down Expand Up @@ -45,14 +45,52 @@ pub fn adhd_subtypes_male() -> DataFrame {
.unwrap()
}

/// Returns all patients who have ADHD-PH
pub fn patient_info_has_adhd_hyperactive() -> DataFrame {
load_patient_info(false)
.filter(
col("ADHD").eq(1).and(col("ADD").eq(0))
)
.apply_gender_age_adhd_type_translation()
.select_patient_info_columns()
.collect()
.unwrap()
}

/// Returns all patients who have ADHD-PI
/// Note - there are not actually any patients who are explicitly PI types reported in the dataset.
#[deprecated]
pub fn patient_info_has_adhd_inattentive() -> DataFrame {
load_patient_info(false)
.filter(
col("ADD").eq(1).and(col("ADHD").eq(0))
)
.apply_gender_age_adhd_type_translation()
.select_patient_info_columns()
.collect()
.unwrap()
}

/// Returns all patients who have ADHD-C
pub fn patient_info_has_adhd_combined() -> DataFrame {
load_patient_info(false)
.filter(
col("ADHD").eq(1).and(col("ADD").eq(1))
)
.apply_gender_age_adhd_type_translation()
.select_patient_info_columns()
.collect()
.unwrap()
}


#[cfg(test)]
mod test {
use super::*;
use polars::export::arrow::legacy::utils::CustomIterTools;
use polars::prelude::NamedFrom;
use polars::series::Series;

use crate::frames::subtypes::{adhd_subtypes_female, adhd_subtypes_male, adhd_subtypes_with_gender_and_age};

#[test]
fn loads_adhd_subtypes_with_gender_and_age() {
Expand All @@ -75,4 +113,31 @@ mod test {
assert_eq!(df.column("Gender").unwrap().tail(Some(1)), Series::new("Gender", &["Male"]));
assert!(df.column("Gender").unwrap().iter().all_equal());
}

#[test]
fn loads_all_patients_adhd_primary_hyperactive() {
let df = patient_info_has_adhd_hyperactive();
assert!(!df.is_empty());
assert_eq!(df.column("ADHD Type").unwrap().tail(Some(1)), Series::new("ADHD Type", &["ADHD-PH"]));
assert!(df.column("ADHD Type").unwrap().iter().all_equal());
}

#[deprecated]
/// This test always fails because there are no patients matching this criteria.
/// Leaving this here more for informational purposes than anything.
fn loads_all_patients_adhd_primary_inattentive() {
let df = patient_info_has_adhd_inattentive();
assert!(!df.is_empty());
assert_eq!(df.column("ADHD Type").unwrap().tail(Some(1)), Series::new("ADHD Type", &["ADHD-PI"]));
assert!(df.column("ADHD Type").unwrap().iter().all_equal());
}

#[test]
fn loads_all_patients_adhd_combined_type() {
let df = patient_info_has_adhd_combined();
assert!(!df.is_empty());
assert_eq!(df.column("ADHD Type").unwrap().tail(Some(1)), Series::new("ADHD Type", &["ADHD-C"]));
assert!(df.column("ADHD Type").unwrap().iter().all_equal());
}

}

0 comments on commit c1a98ea

Please sign in to comment.