Skip to content

Commit 5abbc48

Browse files
jturner314LukeMathWalker
authored andcommitted
Make argmin/max_skipnan use EmptyInput error type (#37)
Neither method uses the `UndefinedOrder` variant, so there's no reason to use the `MinMaxError` enum instead of just the `EmptyInput` struct.
1 parent 02cf558 commit 5abbc48

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

src/quantile/mod.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ where
4545

4646
/// Finds the index of the minimum value of the array skipping NaN values.
4747
///
48-
/// Returns `Err(MinMaxError::EmptyInput)` if the array is empty or none of the values in the array
48+
/// Returns `Err(EmptyInput)` if the array is empty or none of the values in the array
4949
/// are non-NaN values.
5050
///
5151
/// Even if there are multiple (equal) elements that are minima, only one
@@ -65,7 +65,7 @@ where
6565
/// [2., 0., 6.]];
6666
/// assert_eq!(a.argmin_skipnan(), Ok((1, 1)));
6767
/// ```
68-
fn argmin_skipnan(&self) -> Result<D::Pattern, MinMaxError>
68+
fn argmin_skipnan(&self) -> Result<D::Pattern, EmptyInput>
6969
where
7070
A: MaybeNan,
7171
A::NotNan: Ord;
@@ -130,7 +130,7 @@ where
130130

131131
/// Finds the index of the maximum value of the array skipping NaN values.
132132
///
133-
/// Returns `Err(MinMaxError::EmptyInput)` if the array is empty or none of the values in the array
133+
/// Returns `Err(EmptyInput)` if the array is empty or none of the values in the array
134134
/// are non-NaN values.
135135
///
136136
/// Even if there are multiple (equal) elements that are maxima, only one
@@ -150,7 +150,7 @@ where
150150
/// [2., 0., 6.]];
151151
/// assert_eq!(a.argmax_skipnan(), Ok((1, 2)));
152152
/// ```
153-
fn argmax_skipnan(&self) -> Result<D::Pattern, MinMaxError>
153+
fn argmax_skipnan(&self) -> Result<D::Pattern, EmptyInput>
154154
where
155155
A: MaybeNan,
156156
A::NotNan: Ord;
@@ -319,7 +319,7 @@ where
319319
Ok(current_pattern_min)
320320
}
321321

322-
fn argmin_skipnan(&self) -> Result<D::Pattern, MinMaxError>
322+
fn argmin_skipnan(&self) -> Result<D::Pattern, EmptyInput>
323323
where
324324
A: MaybeNan,
325325
A::NotNan: Ord,
@@ -337,7 +337,7 @@ where
337337
if min.is_some() {
338338
Ok(pattern_min)
339339
} else {
340-
Err(MinMaxError::EmptyInput)
340+
Err(EmptyInput)
341341
}
342342
}
343343

@@ -386,7 +386,7 @@ where
386386
Ok(current_pattern_max)
387387
}
388388

389-
fn argmax_skipnan(&self) -> Result<D::Pattern, MinMaxError>
389+
fn argmax_skipnan(&self) -> Result<D::Pattern, EmptyInput>
390390
where
391391
A: MaybeNan,
392392
A::NotNan: Ord,
@@ -404,7 +404,7 @@ where
404404
if max.is_some() {
405405
Ok(pattern_max)
406406
} else {
407-
Err(MinMaxError::EmptyInput)
407+
Err(EmptyInput)
408408
}
409409
}
410410

tests/quantile.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use itertools::izip;
1010
use ndarray::array;
1111
use ndarray::prelude::*;
1212
use ndarray_stats::{
13-
errors::{MinMaxError, QuantileError},
13+
errors::{EmptyInput, MinMaxError, QuantileError},
1414
interpolate::{Higher, Interpolate, Linear, Lower, Midpoint, Nearest},
1515
Quantile1dExt, QuantileExt,
1616
};
@@ -51,10 +51,10 @@ fn test_argmin_skipnan() {
5151
assert_eq!(a.argmin_skipnan(), Ok((1, 0)));
5252

5353
let a: Array2<f64> = array![[], []];
54-
assert_eq!(a.argmin_skipnan(), Err(MinMaxError::EmptyInput));
54+
assert_eq!(a.argmin_skipnan(), Err(EmptyInput));
5555

5656
let a = arr2(&[[::std::f64::NAN; 2]; 2]);
57-
assert_eq!(a.argmin_skipnan(), Err(MinMaxError::EmptyInput));
57+
assert_eq!(a.argmin_skipnan(), Err(EmptyInput));
5858
}
5959

6060
quickcheck! {
@@ -63,7 +63,7 @@ quickcheck! {
6363
let min = a.min_skipnan();
6464
let argmin = a.argmin_skipnan();
6565
if min.is_none() {
66-
argmin == Err(MinMaxError::EmptyInput)
66+
argmin == Err(EmptyInput)
6767
} else {
6868
a[argmin.unwrap()] == *min
6969
}
@@ -134,10 +134,10 @@ fn test_argmax_skipnan() {
134134
assert_eq!(a.argmax_skipnan(), Ok((1, 2)));
135135

136136
let a: Array2<f64> = array![[], []];
137-
assert_eq!(a.argmax_skipnan(), Err(MinMaxError::EmptyInput));
137+
assert_eq!(a.argmax_skipnan(), Err(EmptyInput));
138138

139139
let a = arr2(&[[::std::f64::NAN; 2]; 2]);
140-
assert_eq!(a.argmax_skipnan(), Err(MinMaxError::EmptyInput));
140+
assert_eq!(a.argmax_skipnan(), Err(EmptyInput));
141141
}
142142

143143
quickcheck! {
@@ -146,7 +146,7 @@ quickcheck! {
146146
let max = a.max_skipnan();
147147
let argmax = a.argmax_skipnan();
148148
if max.is_none() {
149-
argmax == Err(MinMaxError::EmptyInput)
149+
argmax == Err(EmptyInput)
150150
} else {
151151
a[argmax.unwrap()] == *max
152152
}

0 commit comments

Comments
 (0)