You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2021/06/06 11:03:31 UTC

[GitHub] [arrow-rs] alamb commented on a change in pull request #414: Doctests for DecimalArray.

alamb commented on a change in pull request #414:
URL: https://github.com/apache/arrow-rs/pull/414#discussion_r646115328



##########
File path: arrow/src/array/array_binary.rs
##########
@@ -613,6 +613,32 @@ impl Array for FixedSizeBinaryArray {
 }
 
 /// A type of `DecimalArray` whose elements are binaries.
+///
+/// # Examples
+///
+/// ```
+///    use arrow::array::{ArrayData, Array, DecimalArray};
+///    use arrow::buffer::Buffer;
+///    use arrow::datatypes::DataType;
+///    // let val_8887: [u8; 16] = [192, 219, 180, 17, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
+///    // let val_neg_8887: [u8; 16] = [64, 36, 75, 238, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255];
+///    let values: [u8; 32] = [
+///        192, 219, 180, 17, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 64, 36, 75, 238, 253,
+///        255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
+///    ];
+///    let array_data = ArrayData::builder(DataType::Decimal(23, 6))
+///        .len(2)
+///        .add_buffer(Buffer::from(&values[..]))
+///        .build();
+///    let decimal_array = DecimalArray::from(array_data);
+///    assert_eq!(2, decimal_array.len());
+///    assert_eq!(8_887_000_000, decimal_array.value(0));
+///    assert_eq!(-8_887_000_000, decimal_array.value(1));
+///    assert_eq!(16, decimal_array.value_length());
+///    assert_eq!(23, decimal_array.precision());
+///    assert_eq!(6, decimal_array.scale());

Review comment:
       @alippai has an improvement for string formatting decimal values in https://github.com/apache/arrow-rs/pull/406
   
   If he adds the method to `DecimalArray` in https://github.com/apache/arrow-rs/pull/406#discussion_r646114701 it would be neat to also add it to the doc test. 

##########
File path: arrow/src/array/array_binary.rs
##########
@@ -613,6 +613,32 @@ impl Array for FixedSizeBinaryArray {
 }
 
 /// A type of `DecimalArray` whose elements are binaries.
+///
+/// # Examples
+///
+/// ```
+///    use arrow::array::{ArrayData, Array, DecimalArray};

Review comment:
       I think using the `DecimalBuilder` to construct a DecimalArray may make for a better example:
   
   For example, here:  https://github.com/apache/arrow-rs/blob/master/arrow/src/array/builder.rs#L2856




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org