From 32bd3653b73f93ab035043e54ab8386d3ba575c9 Mon Sep 17 00:00:00 2001 From: Jim Turner Date: Wed, 10 Apr 2019 21:03:54 -0400 Subject: [PATCH] Make argmin/max_skipnan use EmptyInput error type Neither method uses the `UndefinedOrder` variant, so there's no reason to use the `MinMaxError` enum instead of just the `EmptyInput` struct. --- src/quantile/mod.rs | 16 ++++++++-------- tests/quantile.rs | 14 +++++++------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/quantile/mod.rs b/src/quantile/mod.rs index 3926e24f..19ba5c02 100644 --- a/src/quantile/mod.rs +++ b/src/quantile/mod.rs @@ -45,7 +45,7 @@ where /// Finds the index of the minimum value of the array skipping NaN values. /// - /// Returns `Err(MinMaxError::EmptyInput)` if the array is empty or none of the values in the array + /// Returns `Err(EmptyInput)` if the array is empty or none of the values in the array /// are non-NaN values. /// /// Even if there are multiple (equal) elements that are minima, only one @@ -65,7 +65,7 @@ where /// [2., 0., 6.]]; /// assert_eq!(a.argmin_skipnan(), Ok((1, 1))); /// ``` - fn argmin_skipnan(&self) -> Result + fn argmin_skipnan(&self) -> Result where A: MaybeNan, A::NotNan: Ord; @@ -130,7 +130,7 @@ where /// Finds the index of the maximum value of the array skipping NaN values. /// - /// Returns `Err(MinMaxError::EmptyInput)` if the array is empty or none of the values in the array + /// Returns `Err(EmptyInput)` if the array is empty or none of the values in the array /// are non-NaN values. /// /// Even if there are multiple (equal) elements that are maxima, only one @@ -150,7 +150,7 @@ where /// [2., 0., 6.]]; /// assert_eq!(a.argmax_skipnan(), Ok((1, 2))); /// ``` - fn argmax_skipnan(&self) -> Result + fn argmax_skipnan(&self) -> Result where A: MaybeNan, A::NotNan: Ord; @@ -319,7 +319,7 @@ where Ok(current_pattern_min) } - fn argmin_skipnan(&self) -> Result + fn argmin_skipnan(&self) -> Result where A: MaybeNan, A::NotNan: Ord, @@ -337,7 +337,7 @@ where if min.is_some() { Ok(pattern_min) } else { - Err(MinMaxError::EmptyInput) + Err(EmptyInput) } } @@ -386,7 +386,7 @@ where Ok(current_pattern_max) } - fn argmax_skipnan(&self) -> Result + fn argmax_skipnan(&self) -> Result where A: MaybeNan, A::NotNan: Ord, @@ -404,7 +404,7 @@ where if max.is_some() { Ok(pattern_max) } else { - Err(MinMaxError::EmptyInput) + Err(EmptyInput) } } diff --git a/tests/quantile.rs b/tests/quantile.rs index 36999089..7fefb277 100644 --- a/tests/quantile.rs +++ b/tests/quantile.rs @@ -10,7 +10,7 @@ use itertools::izip; use ndarray::array; use ndarray::prelude::*; use ndarray_stats::{ - errors::{MinMaxError, QuantileError}, + errors::{EmptyInput, MinMaxError, QuantileError}, interpolate::{Higher, Interpolate, Linear, Lower, Midpoint, Nearest}, Quantile1dExt, QuantileExt, }; @@ -51,10 +51,10 @@ fn test_argmin_skipnan() { assert_eq!(a.argmin_skipnan(), Ok((1, 0))); let a: Array2 = array![[], []]; - assert_eq!(a.argmin_skipnan(), Err(MinMaxError::EmptyInput)); + assert_eq!(a.argmin_skipnan(), Err(EmptyInput)); let a = arr2(&[[::std::f64::NAN; 2]; 2]); - assert_eq!(a.argmin_skipnan(), Err(MinMaxError::EmptyInput)); + assert_eq!(a.argmin_skipnan(), Err(EmptyInput)); } quickcheck! { @@ -63,7 +63,7 @@ quickcheck! { let min = a.min_skipnan(); let argmin = a.argmin_skipnan(); if min.is_none() { - argmin == Err(MinMaxError::EmptyInput) + argmin == Err(EmptyInput) } else { a[argmin.unwrap()] == *min } @@ -134,10 +134,10 @@ fn test_argmax_skipnan() { assert_eq!(a.argmax_skipnan(), Ok((1, 2))); let a: Array2 = array![[], []]; - assert_eq!(a.argmax_skipnan(), Err(MinMaxError::EmptyInput)); + assert_eq!(a.argmax_skipnan(), Err(EmptyInput)); let a = arr2(&[[::std::f64::NAN; 2]; 2]); - assert_eq!(a.argmax_skipnan(), Err(MinMaxError::EmptyInput)); + assert_eq!(a.argmax_skipnan(), Err(EmptyInput)); } quickcheck! { @@ -146,7 +146,7 @@ quickcheck! { let max = a.max_skipnan(); let argmax = a.argmax_skipnan(); if max.is_none() { - argmax == Err(MinMaxError::EmptyInput) + argmax == Err(EmptyInput) } else { a[argmax.unwrap()] == *max }