Skip to content

Commit 8710ea8

Browse files
Fixed failing tests for ks_onesample
1 parent 94b17d4 commit 8710ea8

1 file changed

Lines changed: 18 additions & 4 deletions

File tree

src/stats_tests/ks_test.rs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,11 +213,25 @@ pub fn ks_onesample<T>(
213213
where
214214
T: ContinuousCDF<f64, f64>,
215215
{
216-
let sorted_iter = match nan_policy {
217-
NaNPolicy::Propogate => return Ok((f64::NAN, f64::NAN)),
218-
NaNPolicy::Emit => return Err(KSTestError::SampleContainsNaN),
219-
NaNPolicy::Error => data.into_sorted_iter().filter(|x| !x.is_nan()),
216+
fn keep_all(_x: &f64) -> bool {
217+
true
218+
}
219+
fn keep_non_nan(x: &f64) -> bool {
220+
!x.is_nan()
221+
}
222+
let mut temp_sorted_iter = data.into_sorted_iter();
223+
let filter_pred = match nan_policy {
224+
NaNPolicy::Propogate if temp_sorted_iter.any(f64::is_nan) => {
225+
return Ok((f64::NAN, f64::NAN));
226+
}
227+
NaNPolicy::Error if temp_sorted_iter.any(f64::is_nan) => {
228+
return Err(KSTestError::SampleContainsNaN);
229+
}
230+
NaNPolicy::Emit => keep_non_nan,
231+
_ => keep_all,
220232
};
233+
let sorted_iter = data.into_sorted_iter().filter(filter_pred);
234+
println!("{}", sorted_iter.clone().any(|x| x.is_nan()));
221235

222236
let n = sorted_iter.clone().count() as f64;
223237
if (n as usize) < 1 {

0 commit comments

Comments
 (0)