polars_core/chunked_array/builder/
null.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
use arrow::legacy::array::null::MutableNullArray;

use super::*;
use crate::series::implementations::null::NullChunked;

#[derive(Clone)]
pub struct NullChunkedBuilder {
    array_builder: MutableNullArray,
    pub(crate) field: Field,
}

impl NullChunkedBuilder {
    pub fn new(name: PlSmallStr, len: usize) -> Self {
        let array_builder = MutableNullArray::new(len);

        NullChunkedBuilder {
            array_builder,
            field: Field::new(name, DataType::Null),
        }
    }

    /// Appends a null slot into the builder
    #[inline]
    pub fn append_null(&mut self) {
        self.array_builder.push_null()
    }

    pub fn finish(mut self) -> NullChunked {
        let arr = self.array_builder.as_box();
        let ca = NullChunked::new(self.field.name().clone(), arr.len());
        ca
    }

    pub fn shrink_to_fit(&mut self) {
        self.array_builder.shrink_to_fit()
    }
}