Skip to content

Commit f211d47

Browse files
committed
Misc code clean up
1 parent 95cc35f commit f211d47

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

src/models.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,7 @@ pub struct RequestData {
146146
custom = "validate_shape"
147147
)]
148148
pub shape: Option<Vec<usize>>,
149-
/// Axis over which to perform the reduction operation
150-
// pub axis: Option<usize>,
149+
/// Axis or axes over which to perform the reduction operation
151150
#[serde(default)]
152151
pub axis: ReductionAxes,
153152
/// Order of the multi-dimensional array
@@ -252,18 +251,20 @@ fn validate_request_data(request_data: &RequestData) -> Result<(), ValidationErr
252251
match (&request_data.shape, &request_data.axis) {
253252
(Some(shape), ReductionAxes::One(axis)) => {
254253
if *axis > shape.len() - 1 {
255-
return Err(ValidationError::new("Axis must be within shape"));
254+
return Err(ValidationError::new("Reduction axis must be within shape"));
256255
}
257256
}
258257
(Some(shape), ReductionAxes::Multi(axes)) => {
259258
if axes.len() >= shape.len() {
260259
return Err(ValidationError::new(
261-
"Number of reduction axes must be less than length of shape",
260+
"Number of reduction axes must be less than length of shape - to reduce over all axes omit the axis field completely",
262261
));
263262
}
264263
for ax in axes {
265264
if *ax > shape.len() - 1 {
266-
return Err(ValidationError::new("All axes must be within shape"));
265+
return Err(ValidationError::new(
266+
"All reduction axes must be within shape",
267+
));
267268
}
268269
}
269270
}
@@ -275,7 +276,7 @@ fn validate_request_data(request_data: &RequestData) -> Result<(), ValidationErr
275276
// Validate missing specification
276277
if let Some(missing) = &request_data.missing {
277278
missing.validate(request_data.dtype)?;
278-
}
279+
};
279280

280281
Ok(())
281282
}
@@ -288,7 +289,8 @@ pub struct Response {
288289
pub dtype: DType,
289290
/// Shape of the response
290291
pub shape: Vec<usize>,
291-
/// Number of non-missing elements operated on to generate response
292+
/// Number of non-missing elements operated
293+
/// along each reduction axis
292294
pub count: Vec<i64>,
293295
}
294296

@@ -720,7 +722,7 @@ mod tests {
720722
}
721723

722724
#[test]
723-
#[should_panic(expected = "Axis must be within shape")]
725+
#[should_panic(expected = "Reduction axis must be within shape")]
724726
fn test_axis_gt_shape() {
725727
let mut request_data = test_utils::get_test_request_data();
726728
request_data.axis = ReductionAxes::One(2);
@@ -790,7 +792,6 @@ mod tests {
790792
fn test_missing_invalid_value_for_dtype() {
791793
let mut request_data = test_utils::get_test_request_data();
792794
request_data.missing = Some(Missing::MissingValue(i64::max_value().into()));
793-
println!("{:?}", request_data.validate());
794795
request_data.validate().unwrap()
795796
}
796797

0 commit comments

Comments
 (0)