polars_core/chunked_array/
to_vec.rs1use either::Either;
2
3use crate::prelude::*;
4
5impl<T: PolarsNumericType> ChunkedArray<T> {
6 pub fn to_vec(&self) -> Vec<Option<T::Native>> {
8 let mut buf = Vec::with_capacity(self.len());
9 for arr in self.downcast_iter() {
10 buf.extend(arr.into_iter().map(|v| v.copied()))
11 }
12 buf
13 }
14
15 pub fn to_vec_null_aware(&self) -> Either<Vec<T::Native>, Vec<Option<T::Native>>> {
17 if self.null_count() == 0 {
18 let mut buf = Vec::with_capacity(self.len());
19
20 for arr in self.downcast_iter() {
21 buf.extend_from_slice(arr.values())
22 }
23 Either::Left(buf)
24 } else {
25 Either::Right(self.to_vec())
26 }
27 }
28}