polars_core/chunked_array/builder/
null.rs
1use arrow::legacy::array::null::MutableNullArray;
2
3use super::*;
4use crate::series::implementations::null::NullChunked;
5
6#[derive(Clone)]
7pub struct NullChunkedBuilder {
8 array_builder: MutableNullArray,
9 pub(crate) field: Field,
10}
11
12impl NullChunkedBuilder {
13 pub fn new(name: PlSmallStr, len: usize) -> Self {
14 let array_builder = MutableNullArray::new(len);
15
16 NullChunkedBuilder {
17 array_builder,
18 field: Field::new(name, DataType::Null),
19 }
20 }
21
22 #[inline]
24 pub fn append_null(&mut self) {
25 self.array_builder.push_null()
26 }
27
28 pub fn finish(mut self) -> NullChunked {
29 let arr = self.array_builder.as_box();
30 NullChunked::new(self.field.name().clone(), arr.len())
31 }
32
33 pub fn shrink_to_fit(&mut self) {
34 self.array_builder.shrink_to_fit()
35 }
36}