Repository: jorgecarleitao/arrow2
Pull request #1115 (2022-06-28 10:10:31)

Added test for scalar division

codecov[bot]: # [Codecov](https://codecov.io/gh/jorgecarleitao/arrow2/pull/1115?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Jorge+Leitao) Report
> Merging [#1115](https://codecov.io/gh/jorgecarleitao/arrow2/pull/1115?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Jorge+Leitao) (efb5158) into [main](https://codecov.io/gh/jorgecarleitao/arrow2/commit/3b05377870ea63a63b369814d29b6fea0d584b17?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Jorge+Leitao) (3b05377) will **increase** coverage by `0.12%`.
> The diff coverage is `n/a`.

```diff
@@            Coverage Diff             @@
##             main    #1115      +/-   ##
==========================================
+ Coverage   82.36%   82.48%   +0.12%     
==========================================
  Files         367      367              
  Lines       35382    35382              
==========================================
+ Hits        29141    29185      +44     
+ Misses       6241     6197      -44     
```


| [Impacted Files](https://codecov.io/gh/jorgecarleitao/arrow2/pull/1115?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Jorge+Leitao) | Coverage Δ | |
|---|---|---|
| [src/io/ipc/read/reader.rs](https://codecov.io/gh/jorgecarleitao/arrow2/pull/1115/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Jorge+Leitao#diff-c3JjL2lvL2lwYy9yZWFkL3JlYWRlci5ycw==) | `96.38% <0.00%> (+0.36%)` | :arrow_up: |
| [src/array/utf8/mod.rs](https://codecov.io/gh/jorgecarleitao/arrow2/pull/1115/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Jorge+Leitao#diff-c3JjL2FycmF5L3V0ZjgvbW9kLnJz) | `86.58% <0.00%> (+0.95%)` | :arrow_up: |
| [src/array/binary/mod.rs](https://codecov.io/gh/jorgecarleitao/arrow2/pull/1115/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Jorge+Leitao#diff-c3JjL2FycmF5L2JpbmFyeS9tb2QucnM=) | `90.12% <0.00%> (+1.23%)` | :arrow_up: |
| [src/io/ipc/read/array/primitive.rs](https://codecov.io/gh/jorgecarleitao/arrow2/pull/1115/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Jorge+Leitao#diff-c3JjL2lvL2lwYy9yZWFkL2FycmF5L3ByaW1pdGl2ZS5ycw==) | `98.11% <0.00%> (+7.54%)` | :arrow_up: |
| [src/io/ipc/read/array/boolean.rs](https://codecov.io/gh/jorgecarleitao/arrow2/pull/1115/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Jorge+Leitao#diff-c3JjL2lvL2lwYy9yZWFkL2FycmF5L2Jvb2xlYW4ucnM=) | `97.91% <0.00%> (+8.33%)` | :arrow_up: |
| [src/compute/arithmetics/decimal/div.rs](https://codecov.io/gh/jorgecarleitao/arrow2/pull/1115/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Jorge+Leitao#diff-c3JjL2NvbXB1dGUvYXJpdGhtZXRpY3MvZGVjaW1hbC9kaXYucnM=) | `95.39% <0.00%> (+19.07%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/jorgecarleitao/arrow2/pull/1115?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Jorge+Leitao).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Jorge+Leitao)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/jorgecarleitao/arrow2/pull/1115?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Jorge+Leitao). Last update [3b05377...efb5158](https://codecov.io/gh/jorgecarleitao/arrow2/pull/1115?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Jorge+Leitao). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Jorge+Leitao).


Patch:
diff --git a/src/array/fixed_size_binary/iterator.rs b/src/array/fixed_size_binary/iterator.rs
index aa60abfbfe..0e6c5c24c0 100644
--- a/src/array/fixed_size_binary/iterator.rs
+++ b/src/array/fixed_size_binary/iterator.rs
@@ -59,11 +59,11 @@ impl<'a> FixedSizeBinaryArray {
     pub fn iter(
         &'a self,
     ) -> ZipValidity<'a, &'a [u8], FixedSizeBinaryValuesIter<'a, FixedSizeBinaryArray>> {
-        zip_validity(self.iter_values(), self.validity.as_ref().map(|x| x.iter()))
+        zip_validity(self.values_iter(), self.validity.as_ref().map(|x| x.iter()))
     }
 
     /// Returns iterator over the values of [`FixedSizeBinaryArray`]
-    pub fn iter_values(&'a self) -> FixedSizeBinaryValuesIter<'a, FixedSizeBinaryArray> {
+    pub fn values_iter(&'a self) -> FixedSizeBinaryValuesIter<'a, FixedSizeBinaryArray> {
         FixedSizeBinaryValuesIter::new(self)
     }
 }


Test patch:
diff --git a/tests/it/compute/arithmetics/decimal/div.rs b/tests/it/compute/arithmetics/decimal/div.rs
index 55cca8d303..39138d05dd 100644
--- a/tests/it/compute/arithmetics/decimal/div.rs
+++ b/tests/it/compute/arithmetics/decimal/div.rs
@@ -1,9 +1,12 @@
 #![allow(clippy::zero_prefixed_literal, clippy::inconsistent_digit_grouping)]
 
 use arrow2::array::*;
-use arrow2::compute::arithmetics::decimal::{adaptive_div, checked_div, div, saturating_div};
+use arrow2::compute::arithmetics::decimal::{
+    adaptive_div, checked_div, div, div_scalar, saturating_div,
+};
 use arrow2::compute::arithmetics::{ArrayCheckedDiv, ArrayDiv};
 use arrow2::datatypes::DataType;
+use arrow2::scalar::PrimitiveScalar;
 
 #[test]
 fn test_divide_normal() {
@@ -65,6 +68,28 @@ fn test_divide_panic() {
     div(&a, &b);
 }
 
+#[test]
+fn test_div_scalar() {
+    //   222.222 -->  222222000
+    //   123.456 -->     123456
+    // --------       ---------
+    //     1.800 <--       1800
+    let a = PrimitiveArray::from([Some(222_222i128), None]).to(DataType::Decimal(7, 3));
+    let b = PrimitiveScalar::from(Some(123_456i128)).to(DataType::Decimal(7, 3));
+    let result = div_scalar(&a, &b);
+
+    let expected = PrimitiveArray::from([Some(1_800i128), None]).to(DataType::Decimal(7, 3));
+    assert_eq!(result, expected);
+}
+
+#[test]
+#[should_panic(expected = "Overflow in multiplication presented for precision 5")]
+fn test_divide_scalar_panic() {
+    let a = PrimitiveArray::from([Some(99999i128)]).to(DataType::Decimal(5, 2));
+    let b = PrimitiveScalar::from(Some(000_01i128)).to(DataType::Decimal(5, 2));
+    div_scalar(&a, &b);
+}
+
 #[test]
 fn test_divide_saturating() {
     let a = PrimitiveArray::from([