Repository: jorgecarleitao/arrow2
Pull request #334 (2021-08-24 18:43:00)

Fixed error in displaying dictionaries with nulls in values
They were displayed as their values, even if they were null.

codecov[bot]: # [Codecov](https://codecov.io/gh/jorgecarleitao/arrow2/pull/334?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Jorge+Leitao) Report
> Merging [#334](https://codecov.io/gh/jorgecarleitao/arrow2/pull/334?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Jorge+Leitao) (6ebce50) into [main](https://codecov.io/gh/jorgecarleitao/arrow2/commit/a9932a68d2cd45d9988468664bee7c9e08fed6be?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Jorge+Leitao) (a9932a6) will **increase** coverage by `0.01%`.
> The diff coverage is `100.00%`.

[![Impacted file tree graph](https://codecov.io/gh/jorgecarleitao/arrow2/pull/334/graphs/tree.svg?width=650&height=150&src=pr&token=AgyTF60R3D&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Jorge+Leitao)](https://codecov.io/gh/jorgecarleitao/arrow2/pull/334?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Jorge+Leitao)

```diff
@@            Coverage Diff             @@
##             main     #334      +/-   ##
==========================================
+ Coverage   80.95%   80.96%   +0.01%     
==========================================
  Files         325      325              
  Lines       21069    21081      +12     
==========================================
+ Hits        17057    17069      +12     
  Misses       4012     4012              
```


| [Impacted Files](https://codecov.io/gh/jorgecarleitao/arrow2/pull/334?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Jorge+Leitao) | Coverage Δ | |
|---|---|---|
| [src/array/display.rs](https://codecov.io/gh/jorgecarleitao/arrow2/pull/334/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Jorge+Leitao#diff-c3JjL2FycmF5L2Rpc3BsYXkucnM=) | `57.89% <ø> (ø)` | |
| [tests/it/io/print.rs](https://codecov.io/gh/jorgecarleitao/arrow2/pull/334/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Jorge+Leitao#diff-dGVzdHMvaXQvaW8vcHJpbnQucnM=) | `100.00% <100.00%> (ø)` | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/jorgecarleitao/arrow2/pull/334?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/334?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Jorge+Leitao). Last update [a9932a6...6ebce50](https://codecov.io/gh/jorgecarleitao/arrow2/pull/334?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/display.rs b/src/array/display.rs
index d049c408c8..7a216993b5 100644
--- a/src/array/display.rs
+++ b/src/array/display.rs
@@ -24,7 +24,7 @@ macro_rules! dyn_dict {
             .downcast_ref::<DictionaryArray<$ty>>()
             .unwrap();
         let keys = a.keys();
-        let display = get_value_display(a.values().as_ref());
+        let display = get_display(a.values().as_ref());
         Box::new(move |row: usize| display(keys.value(row) as usize))
     }};
 }


Test patch:
diff --git a/tests/it/io/print.rs b/tests/it/io/print.rs
index bb1618d332..a2ee1b97ef 100644
--- a/tests/it/io/print.rs
+++ b/tests/it/io/print.rs
@@ -116,6 +116,31 @@ fn write_dictionary() -> Result<()> {
     Ok(())
 }
 
+#[test]
+fn dictionary_validities() -> Result<()> {
+    // define a schema.
+    let field_type = DataType::Dictionary(Box::new(DataType::Int32), Box::new(DataType::Int32));
+    let schema = Arc::new(Schema::new(vec![Field::new("d1", field_type, true)]));
+
+    let keys = PrimitiveArray::<i32>::from([Some(1), None, Some(0)]);
+    let values = PrimitiveArray::<i32>::from([None, Some(10)]);
+    let array = DictionaryArray::<i32>::from_data(keys, Arc::new(values));
+
+    let batch = RecordBatch::try_new(schema, vec![Arc::new(array)])?;
+
+    let table = write(&[batch]);
+
+    let expected = vec![
+        "+----+", "| d1 |", "+----+", "| 10 |", "|    |", "|    |", "+----+",
+    ];
+
+    let actual: Vec<&str> = table.lines().collect();
+
+    assert_eq!(expected, actual, "Actual result:\n{}", table);
+
+    Ok(())
+}
+
 /// Generate an array with type $ARRAYTYPE with a numeric value of
 /// $VALUE, and compare $EXPECTED_RESULT to the output of
 /// formatting that array with `write`