|
1 | 1 | use super::bins::Bins;
|
| 2 | +use super::errors::BinsBuildError; |
2 | 3 | use super::strategies::BinsBuildingStrategy;
|
3 | 4 | use itertools::izip;
|
4 | 5 | use ndarray::{ArrayBase, Axis, Data, Ix1, Ix2};
|
@@ -169,23 +170,20 @@ where
|
169 | 170 | /// it returns a `GridBuilder` instance that has learned the required parameter
|
170 | 171 | /// to build a [`Grid`] according to the specified [`strategy`].
|
171 | 172 | ///
|
172 |
| - /// It returns `None` if it is not possible to build a [`Grid`] given |
| 173 | + /// It returns `Err` if it is not possible to build a [`Grid`] given |
173 | 174 | /// the observed data according to the chosen [`strategy`].
|
174 | 175 | ///
|
175 | 176 | /// [`Grid`]: struct.Grid.html
|
176 | 177 | /// [`strategy`]: strategies/index.html
|
177 |
| - pub fn from_array<S>(array: &ArrayBase<S, Ix2>) -> Option<Self> |
| 178 | + pub fn from_array<S>(array: &ArrayBase<S, Ix2>) -> Result<Self, BinsBuildError> |
178 | 179 | where
|
179 | 180 | S: Data<Elem = A>,
|
180 | 181 | {
|
181 |
| - let bin_builders: Option<Vec<B>> = array |
| 182 | + let bin_builders = array |
182 | 183 | .axis_iter(Axis(1))
|
183 |
| - .map(|data| match B::from_array(&data) { |
184 |
| - Ok(builder) => Some(builder), |
185 |
| - _ => None, |
186 |
| - }) |
187 |
| - .collect(); |
188 |
| - bin_builders.map(|b| Self { bin_builders: b }) |
| 184 | + .map(|data| B::from_array(&data)) |
| 185 | + .collect::<Result<Vec<B>, BinsBuildError>>()?; |
| 186 | + Ok(Self { bin_builders }) |
189 | 187 | }
|
190 | 188 |
|
191 | 189 | /// Returns a [`Grid`] instance, built accordingly to the specified [`strategy`]
|
|
0 commit comments