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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
use super::RepeatBy;
use crate::prelude::*;
use arrow::array::ListArray;
use polars_arrow::array::ListFromIter;
type LargeListArray = ListArray<i64>;
impl<T> RepeatBy for ChunkedArray<T>
where
T: PolarsNumericType,
{
fn repeat_by(&self, by: &IdxCa) -> ListChunked {
let iter = self
.into_iter()
.zip(by.into_iter())
.map(|(opt_v, opt_by)| opt_by.map(|by| std::iter::repeat(opt_v).take(by as usize)));
ListChunked::from_chunks(
self.name(),
vec![Arc::new(unsafe {
LargeListArray::from_iter_primitive_trusted_len::<T::Native, _, _>(
iter,
T::get_dtype().to_arrow(),
)
})],
)
}
}
impl RepeatBy for BooleanChunked {
fn repeat_by(&self, by: &IdxCa) -> ListChunked {
let iter = self
.into_iter()
.zip(by.into_iter())
.map(|(opt_v, opt_by)| opt_by.map(|by| std::iter::repeat(opt_v).take(by as usize)));
ListChunked::from_chunks(
self.name(),
vec![Arc::new(unsafe {
LargeListArray::from_iter_bool_trusted_len(iter)
})],
)
}
}
impl RepeatBy for Utf8Chunked {
fn repeat_by(&self, by: &IdxCa) -> ListChunked {
let iter = self
.into_iter()
.zip(by.into_iter())
.map(|(opt_v, opt_by)| opt_by.map(|by| std::iter::repeat(opt_v).take(by as usize)));
ListChunked::from_chunks(
self.name(),
vec![Arc::new(unsafe {
LargeListArray::from_iter_utf8_trusted_len(iter, self.len())
})],
)
}
}