Skip to content

Commit

Permalink
fmt + clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
alamb committed Nov 23, 2021
1 parent 7063b5e commit 74b74dd
Showing 1 changed file with 19 additions and 28 deletions.
47 changes: 19 additions & 28 deletions arrow/src/array/data.rs
Expand Up @@ -727,7 +727,7 @@ impl ArrayData {
) -> Result<()> {
// Justification: buffer size was validated above
let offsets = self.typed_offsets::<T>(buffer)?;
if offsets.len() == 0 {
if offsets.is_empty() {
return Ok(());
}

Expand Down Expand Up @@ -2088,9 +2088,8 @@ mod tests {

/// Test that the list of type `data_type` generates correct offset out of bounds errors
fn check_list_offsets<T: ArrowNativeType>(data_type: DataType) {
let values: Int32Array = [Some(1), Some(2), Some(3), Some(4)]
.into_iter()
.collect();
let values: Int32Array =
[Some(1), Some(2), Some(3), Some(4)].into_iter().collect();

// 5 is an invalid offset into a list of only three values
let offsets: Vec<T> = [0, 2, 5, 4]
Expand Down Expand Up @@ -2135,9 +2134,8 @@ mod tests {
expected = "Offset invariant failure: Could not convert end_offset -1 to usize in slot 2"
)]
fn test_validate_list_negative_offsets() {
let values: Int32Array = [Some(1), Some(2), Some(3), Some(4)]
.into_iter()
.collect();
let values: Int32Array =
[Some(1), Some(2), Some(3), Some(4)].into_iter().collect();
let field_type = Field::new("f", values.data_type().clone(), true);
let data_type = DataType::List(Box::new(field_type));

Expand All @@ -2157,7 +2155,6 @@ mod tests {
.unwrap();
}


#[test]
#[should_panic(
expected = "child #0 invalid: Invalid argument error: Value at position 1 out of bounds: -1 (can not convert to usize)"
Expand All @@ -2175,29 +2172,23 @@ mod tests {
);

// purposely create an invalid child data
let dict_data = unsafe { ArrayData::new_unchecked(
dict_data_type,
1,
None,
None,
0,
vec![keys.data().buffers[0].clone()],
vec![values.data().clone()],
)};
let dict_data = unsafe {
ArrayData::new_unchecked(
dict_data_type,
1,
None,
None,
0,
vec![keys.data().buffers[0].clone()],
vec![values.data().clone()],
)
};

// Now, try and create a struct with this invalid child data (and expect an error)
let data_type = DataType::Struct(vec![Field::new("d", dict_data.data_type().clone(), true)]);
let data_type =
DataType::Struct(vec![Field::new("d", dict_data.data_type().clone(), true)]);

ArrayData::try_new(
data_type,
1,
None,
None,
0,
vec![],
vec![dict_data],
)
.unwrap();
ArrayData::try_new(data_type, 1, None, None, 0, vec![], vec![dict_data]).unwrap();
}

/// returns a buffer initialized with some constant value for tests
Expand Down

0 comments on commit 74b74dd

Please sign in to comment.