Skip to content

Commit

Permalink
handle nan
Browse files Browse the repository at this point in the history
  • Loading branch information
m5l14i11 committed Aug 7, 2023
1 parent 61dccd5 commit ede5540
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion ta_lib/core/src/series.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,11 @@ impl Series<f64> {
impl<T: AsRef<[f64]>> From<T> for Series<f64> {
fn from(item: T) -> Self {
Self {
data: item.as_ref().iter().map(|&x| Some(x)).collect(),
data: item
.as_ref()
.iter()
.map(|&x| if x.is_nan() { None } else { Some(x) })
.collect(),
}
}
}
Expand Down Expand Up @@ -185,6 +189,16 @@ mod tests {
assert_eq!(result.len(), expected);
}

#[test]
fn test_from() {
let source = vec![f64::NAN, 1.0, 2.0, 3.0];
let expected = vec![None, Some(1.0), Some(2.0), Some(3.0)];

let result = Series::from(&source);

assert_eq!(result, expected);
}

#[test]
fn test_empty() {
let len = 4;
Expand Down

0 comments on commit ede5540

Please sign in to comment.