Repository: jorgecarleitao/arrow2
Pull request #1029 (2022-05-31 04:25:10)

Added more tests

codecov[bot]: # [Codecov](https://codecov.io/gh/jorgecarleitao/arrow2/pull/1029?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Jorge+Leitao) Report
> Merging [#1029](https://codecov.io/gh/jorgecarleitao/arrow2/pull/1029?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Jorge+Leitao) (72601b6) into [main](https://codecov.io/gh/jorgecarleitao/arrow2/commit/0dbe9222e0ca9becd3b4a20ee61043d8b95ed7f2?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Jorge+Leitao) (0dbe922) will **increase** coverage by `0.32%`.
> The diff coverage is `66.66%`.

```diff
@@            Coverage Diff             @@
##             main    #1029      +/-   ##
==========================================
+ Coverage   72.04%   72.36%   +0.32%     
==========================================
  Files         359      359              
  Lines       19926    19926              
==========================================
+ Hits        14355    14419      +64     
+ Misses       5571     5507      -64     
```


| [Impacted Files](https://codecov.io/gh/jorgecarleitao/arrow2/pull/1029?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Jorge+Leitao) | Coverage Δ | |
|---|---|---|
| [src/array/fixed\_size\_binary/iterator.rs](https://codecov.io/gh/jorgecarleitao/arrow2/pull/1029/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Jorge+Leitao#diff-c3JjL2FycmF5L2ZpeGVkX3NpemVfYmluYXJ5L2l0ZXJhdG9yLnJz) | `74.07% <66.66%> (-3.71%)` | :arrow_down: |
| [src/array/primitive/mutable.rs](https://codecov.io/gh/jorgecarleitao/arrow2/pull/1029/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Jorge+Leitao#diff-c3JjL2FycmF5L3ByaW1pdGl2ZS9tdXRhYmxlLnJz) | `92.79% <0.00%> (+3.38%)` | :arrow_up: |
| [src/bitmap/bitmap\_ops.rs](https://codecov.io/gh/jorgecarleitao/arrow2/pull/1029/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Jorge+Leitao#diff-c3JjL2JpdG1hcC9iaXRtYXBfb3BzLnJz) | `94.69% <0.00%> (+3.78%)` | :arrow_up: |
| [src/array/list/ffi.rs](https://codecov.io/gh/jorgecarleitao/arrow2/pull/1029/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Jorge+Leitao#diff-c3JjL2FycmF5L2xpc3QvZmZpLnJz) | `96.55% <0.00%> (+31.03%)` | :arrow_up: |
| [src/array/utf8/ffi.rs](https://codecov.io/gh/jorgecarleitao/arrow2/pull/1029/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Jorge+Leitao#diff-c3JjL2FycmF5L3V0ZjgvZmZpLnJz) | `96.42% <0.00%> (+32.14%)` | :arrow_up: |
| [src/array/binary/ffi.rs](https://codecov.io/gh/jorgecarleitao/arrow2/pull/1029/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Jorge+Leitao#diff-c3JjL2FycmF5L2JpbmFyeS9mZmkucnM=) | `96.42% <0.00%> (+32.14%)` | :arrow_up: |
| [src/array/boolean/ffi.rs](https://codecov.io/gh/jorgecarleitao/arrow2/pull/1029/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Jorge+Leitao#diff-c3JjL2FycmF5L2Jvb2xlYW4vZmZpLnJz) | `95.83% <0.00%> (+33.33%)` | :arrow_up: |
| [src/array/primitive/ffi.rs](https://codecov.io/gh/jorgecarleitao/arrow2/pull/1029/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Jorge+Leitao#diff-c3JjL2FycmF5L3ByaW1pdGl2ZS9mZmkucnM=) | `95.83% <0.00%> (+33.33%)` | :arrow_up: |
| [src/array/fixed\_size\_binary/ffi.rs](https://codecov.io/gh/jorgecarleitao/arrow2/pull/1029/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Jorge+Leitao#diff-c3JjL2FycmF5L2ZpeGVkX3NpemVfYmluYXJ5L2ZmaS5ycw==) | `96.00% <0.00%> (+36.00%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/jorgecarleitao/arrow2/pull/1029?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/1029?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Jorge+Leitao). Last update [0dbe922...72601b6](https://codecov.io/gh/jorgecarleitao/arrow2/pull/1029?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 cc88967667..aa60abfbfe 100644
--- a/src/array/fixed_size_binary/iterator.rs
+++ b/src/array/fixed_size_binary/iterator.rs
@@ -32,10 +32,9 @@ impl<'a, T: FixedSizeBinaryValues> Iterator for FixedSizeBinaryValuesIter<'a, T>
         }
         let index = self.index;
         let r = Some(unsafe {
-            std::slice::from_raw_parts(
-                self.array.values().as_ptr().add(index * self.array.size()),
-                self.array.size(),
-            )
+            self.array
+                .values()
+                .get_unchecked(index * self.array.size()..(index + 1) * self.array.size())
         });
         self.index += 1;
         r


Test patch:
diff --git a/tests/it/array/primitive/mutable.rs b/tests/it/array/primitive/mutable.rs
index 99f897076d..2de49822c3 100644
--- a/tests/it/array/primitive/mutable.rs
+++ b/tests/it/array/primitive/mutable.rs
@@ -20,6 +20,12 @@ fn from_and_into_data() {
     assert_eq!(c, Some(MutableBitmap::from([true, false])));
 }
 
+#[test]
+fn from_vec() {
+    let a = MutablePrimitiveArray::from_vec(Vec::from([1i32, 0]));
+    assert_eq!(a.len(), 2);
+}
+
 #[test]
 fn to() {
     let a = MutablePrimitiveArray::from_data(
@@ -152,9 +158,10 @@ fn as_box() {
 fn shrink_to_fit_and_capacity() {
     let mut a = MutablePrimitiveArray::<i32>::with_capacity(100);
     a.push(Some(1));
+    a.try_push(None).unwrap();
     assert!(a.capacity() >= 100);
-    a.shrink_to_fit();
-    assert_eq!(a.capacity(), 1);
+    (&mut a as &mut dyn MutableArray).shrink_to_fit();
+    assert_eq!(a.capacity(), 2);
 }
 
 #[test]
@@ -168,7 +175,16 @@ fn only_nulls() {
 
 #[test]
 fn from_trusted_len() {
-    let a = MutablePrimitiveArray::<i32>::from_trusted_len_iter(vec![Some(1), None].into_iter());
+    let a =
+        MutablePrimitiveArray::<i32>::from_trusted_len_iter(vec![Some(1), None, None].into_iter());
+    let a: PrimitiveArray<i32> = a.into();
+    assert_eq!(a.validity(), Some(&Bitmap::from([true, false, false])));
+
+    let a = unsafe {
+        MutablePrimitiveArray::<i32>::from_trusted_len_iter_unchecked(
+            vec![Some(1), None].into_iter(),
+        )
+    };
     let a: PrimitiveArray<i32> = a.into();
     assert_eq!(a.validity(), Some(&Bitmap::from([true, false])));
 }
diff --git a/tests/it/ffi/data.rs b/tests/it/ffi/data.rs
index 39c9400114..08f2334293 100644
--- a/tests/it/ffi/data.rs
+++ b/tests/it/ffi/data.rs
@@ -69,6 +69,13 @@ fn bool() -> Result<()> {
     test_round_trip(data)
 }
 
+#[test]
+fn bool_nullable_sliced() -> Result<()> {
+    let bitmap = Bitmap::from([true, false, false, true]).slice(1, 3);
+    let data = BooleanArray::try_new(DataType::Boolean, [true, true, false].into(), Some(bitmap))?;
+    test_round_trip(data)
+}
+
 #[test]
 fn u32_nullable() -> Result<()> {
     let data = Int32Array::from(&[Some(2), None, Some(1), None]);
@@ -81,6 +88,13 @@ fn u32() -> Result<()> {
     test_round_trip(data)
 }
 
+#[test]
+fn u32_sliced() -> Result<()> {
+    let bitmap = Bitmap::from([true, false, false, true]).slice(1, 3);
+    let data = Int32Array::try_new(DataType::Int32, vec![1, 2, 3].into(), Some(bitmap))?;
+    test_round_trip(data)
+}
+
 #[test]
 fn decimal() -> Result<()> {
     let data = Int128Array::from_slice(&[1, 0, 2, 0]);
@@ -114,6 +128,18 @@ fn utf8() -> Result<()> {
     test_round_trip(data)
 }
 
+#[test]
+fn utf8_sliced() -> Result<()> {
+    let bitmap = Bitmap::from([true, false, false, true]).slice(1, 3);
+    let data = Utf8Array::<i32>::try_new(
+        DataType::Utf8,
+        vec![0, 1, 1, 2].into(),
+        b"ab".to_vec().into(),
+        Some(bitmap),
+    )?;
+    test_round_trip(data)
+}
+
 #[test]
 fn large_utf8() -> Result<()> {
     let data = Utf8Array::<i64>::from(&vec![Some("a"), None, Some("bb"), None]);
@@ -133,6 +159,18 @@ fn binary() -> Result<()> {
     test_round_trip(data)
 }
 
+#[test]
+fn binary_sliced() -> Result<()> {
+    let bitmap = Bitmap::from([true, false, false, true]).slice(1, 3);
+    let data = BinaryArray::<i32>::try_new(
+        DataType::Binary,
+        vec![0, 1, 1, 2].into(),
+        b"ab".to_vec().into(),
+        Some(bitmap),
+    )?;
+    test_round_trip(data)
+}
+
 #[test]
 fn large_binary() -> Result<()> {
     let data =
@@ -160,6 +198,17 @@ fn fixed_size_binary_nullable() -> Result<()> {
     test_round_trip(data)
 }
 
+#[test]
+fn fixed_size_binary_sliced() -> Result<()> {
+    let bitmap = Bitmap::from([true, false, false, true]).slice(1, 3);
+    let data = FixedSizeBinaryArray::try_new(
+        DataType::FixedSizeBinary(2),
+        b"ababab".to_vec().into(),
+        Some(bitmap),
+    )?;
+    test_round_trip(data)
+}
+
 #[test]
 fn list() -> Result<()> {
     let data = vec![
@@ -176,6 +225,20 @@ fn list() -> Result<()> {
     test_round_trip(array)
 }
 
+#[test]
+fn list_sliced() -> Result<()> {
+    let bitmap = Bitmap::from([true, false, false, true]).slice(1, 3);
+
+    let array = ListArray::<i32>::try_new(
+        DataType::List(Box::new(Field::new("a", DataType::Int32, true))),
+        vec![0, 1, 1, 2].into(),
+        Arc::new(PrimitiveArray::<i32>::from_vec(vec![1, 2])),
+        Some(bitmap),
+    )?;
+
+    test_round_trip(array)
+}
+
 #[test]
 fn large_list() -> Result<()> {
     let data = vec![
@@ -193,7 +256,7 @@ fn large_list() -> Result<()> {
 }
 
 #[test]
-fn fixed_list() -> Result<()> {
+fn fixed_size_list() -> Result<()> {
     let data = vec![
         Some(vec![Some(1i32), Some(2), Some(3)]),
         None,
@@ -208,6 +271,19 @@ fn fixed_list() -> Result<()> {
     test_round_trip(array)
 }
 
+#[test]
+fn fixed_size_list_sliced() -> Result<()> {
+    let bitmap = Bitmap::from([true, false, false, true]).slice(1, 3);
+
+    let array = FixedSizeListArray::try_new(
+        DataType::FixedSizeList(Box::new(Field::new("a", DataType::Int32, true)), 2),
+        Arc::new(PrimitiveArray::<i32>::from_vec(vec![1, 2, 3, 4, 5, 6])),
+        Some(bitmap),
+    )?;
+
+    test_round_trip(array)
+}
+
 #[test]
 fn list_list() -> Result<()> {
     let data = vec![