polars_arrow/array/dictionary/
fmt.rs

1use std::fmt::{Debug, Formatter, Result, Write};
2
3use super::super::fmt::{get_display, write_vec};
4use super::{DictionaryArray, DictionaryKey};
5use crate::array::Array;
6
7pub fn write_value<K: DictionaryKey, W: Write>(
8    array: &DictionaryArray<K>,
9    index: usize,
10    null: &'static str,
11    f: &mut W,
12) -> Result {
13    let keys = array.keys();
14    let values = array.values();
15
16    if keys.is_valid(index) {
17        let key = array.key_value(index);
18        get_display(values.as_ref(), null)(f, key)
19    } else {
20        write!(f, "{null}")
21    }
22}
23
24impl<K: DictionaryKey> Debug for DictionaryArray<K> {
25    fn fmt(&self, f: &mut Formatter<'_>) -> Result {
26        let writer = |f: &mut Formatter, index| write_value(self, index, "None", f);
27
28        write!(f, "DictionaryArray")?;
29        write_vec(f, writer, self.validity(), self.len(), "None", false)
30    }
31}