Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pola-rs
GitHub Repository: pola-rs/polars
Path: blob/main/crates/polars-core/src/series/implementations/array.rs
6940 views
1
use std::any::Any;
2
use std::borrow::Cow;
3
4
use self::compare_inner::{TotalEqInner, TotalOrdInner};
5
use self::sort::arg_sort_row_fmt;
6
use super::{IsSorted, StatisticsFlags, private};
7
use crate::chunked_array::AsSinglePtr;
8
use crate::chunked_array::cast::CastOptions;
9
use crate::chunked_array::comparison::*;
10
#[cfg(feature = "algorithm_group_by")]
11
use crate::frame::group_by::*;
12
use crate::prelude::row_encode::_get_rows_encoded_ca_unordered;
13
use crate::prelude::*;
14
use crate::series::implementations::SeriesWrap;
15
16
impl private::PrivateSeries for SeriesWrap<ArrayChunked> {
17
fn compute_len(&mut self) {
18
self.0.compute_len()
19
}
20
fn _field(&self) -> Cow<'_, Field> {
21
Cow::Borrowed(self.0.ref_field())
22
}
23
fn _dtype(&self) -> &DataType {
24
self.0.ref_field().dtype()
25
}
26
27
fn _get_flags(&self) -> StatisticsFlags {
28
self.0.get_flags()
29
}
30
31
fn _set_flags(&mut self, flags: StatisticsFlags) {
32
self.0.set_flags(flags)
33
}
34
35
unsafe fn equal_element(&self, idx_self: usize, idx_other: usize, other: &Series) -> bool {
36
self.0.equal_element(idx_self, idx_other, other)
37
}
38
39
fn vec_hash(
40
&self,
41
build_hasher: PlSeedableRandomStateQuality,
42
buf: &mut Vec<u64>,
43
) -> PolarsResult<()> {
44
_get_rows_encoded_ca_unordered(PlSmallStr::EMPTY, &[self.0.clone().into_column()])?
45
.vec_hash(build_hasher, buf)
46
}
47
48
fn vec_hash_combine(
49
&self,
50
build_hasher: PlSeedableRandomStateQuality,
51
hashes: &mut [u64],
52
) -> PolarsResult<()> {
53
_get_rows_encoded_ca_unordered(PlSmallStr::EMPTY, &[self.0.clone().into_column()])?
54
.vec_hash_combine(build_hasher, hashes)
55
}
56
57
#[cfg(feature = "zip_with")]
58
fn zip_with_same_type(&self, mask: &BooleanChunked, other: &Series) -> PolarsResult<Series> {
59
ChunkZip::zip_with(&self.0, mask, other.as_ref().as_ref()).map(|ca| ca.into_series())
60
}
61
62
#[cfg(feature = "algorithm_group_by")]
63
unsafe fn agg_list(&self, groups: &GroupsType) -> Series {
64
self.0.agg_list(groups)
65
}
66
67
#[cfg(feature = "algorithm_group_by")]
68
fn group_tuples(&self, multithreaded: bool, sorted: bool) -> PolarsResult<GroupsType> {
69
IntoGroupsType::group_tuples(&self.0, multithreaded, sorted)
70
}
71
72
fn add_to(&self, rhs: &Series) -> PolarsResult<Series> {
73
self.0.add_to(rhs)
74
}
75
76
fn subtract(&self, rhs: &Series) -> PolarsResult<Series> {
77
self.0.subtract(rhs)
78
}
79
80
fn multiply(&self, rhs: &Series) -> PolarsResult<Series> {
81
self.0.multiply(rhs)
82
}
83
fn divide(&self, rhs: &Series) -> PolarsResult<Series> {
84
self.0.divide(rhs)
85
}
86
fn remainder(&self, rhs: &Series) -> PolarsResult<Series> {
87
self.0.remainder(rhs)
88
}
89
90
fn into_total_eq_inner<'a>(&'a self) -> Box<dyn TotalEqInner + 'a> {
91
invalid_operation_panic!(into_total_eq_inner, self)
92
}
93
fn into_total_ord_inner<'a>(&'a self) -> Box<dyn TotalOrdInner + 'a> {
94
invalid_operation_panic!(into_total_ord_inner, self)
95
}
96
}
97
98
impl SeriesTrait for SeriesWrap<ArrayChunked> {
99
fn rename(&mut self, name: PlSmallStr) {
100
self.0.rename(name);
101
}
102
103
fn chunk_lengths(&self) -> ChunkLenIter<'_> {
104
self.0.chunk_lengths()
105
}
106
fn name(&self) -> &PlSmallStr {
107
self.0.name()
108
}
109
110
fn chunks(&self) -> &Vec<ArrayRef> {
111
self.0.chunks()
112
}
113
unsafe fn chunks_mut(&mut self) -> &mut Vec<ArrayRef> {
114
self.0.chunks_mut()
115
}
116
fn shrink_to_fit(&mut self) {
117
self.0.shrink_to_fit()
118
}
119
120
fn arg_sort(&self, options: SortOptions) -> IdxCa {
121
let slf = (*self).clone();
122
let slf = slf.into_column();
123
arg_sort_row_fmt(
124
&[slf],
125
options.descending,
126
options.nulls_last,
127
options.multithreaded,
128
)
129
.unwrap()
130
}
131
132
fn sort_with(&self, options: SortOptions) -> PolarsResult<Series> {
133
let idxs = self.arg_sort(options);
134
let mut result = unsafe { self.take_unchecked(&idxs) };
135
result.set_sorted_flag(if options.descending {
136
IsSorted::Descending
137
} else {
138
IsSorted::Ascending
139
});
140
Ok(result)
141
}
142
143
fn slice(&self, offset: i64, length: usize) -> Series {
144
self.0.slice(offset, length).into_series()
145
}
146
147
fn split_at(&self, offset: i64) -> (Series, Series) {
148
let (a, b) = self.0.split_at(offset);
149
(a.into_series(), b.into_series())
150
}
151
152
fn append(&mut self, other: &Series) -> PolarsResult<()> {
153
polars_ensure!(self.0.dtype() == other.dtype(), append);
154
let other = other.array()?;
155
self.0.append(other)
156
}
157
fn append_owned(&mut self, other: Series) -> PolarsResult<()> {
158
polars_ensure!(self.0.dtype() == other.dtype(), append);
159
self.0.append_owned(other.take_inner())
160
}
161
162
fn extend(&mut self, other: &Series) -> PolarsResult<()> {
163
polars_ensure!(self.0.dtype() == other.dtype(), extend);
164
self.0.extend(other.as_ref().as_ref())
165
}
166
167
fn filter(&self, filter: &BooleanChunked) -> PolarsResult<Series> {
168
ChunkFilter::filter(&self.0, filter).map(|ca| ca.into_series())
169
}
170
171
fn take(&self, indices: &IdxCa) -> PolarsResult<Series> {
172
Ok(self.0.take(indices)?.into_series())
173
}
174
175
unsafe fn take_unchecked(&self, indices: &IdxCa) -> Series {
176
self.0.take_unchecked(indices).into_series()
177
}
178
179
fn take_slice(&self, indices: &[IdxSize]) -> PolarsResult<Series> {
180
Ok(self.0.take(indices)?.into_series())
181
}
182
183
unsafe fn take_slice_unchecked(&self, indices: &[IdxSize]) -> Series {
184
self.0.take_unchecked(indices).into_series()
185
}
186
187
fn len(&self) -> usize {
188
self.0.len()
189
}
190
191
fn rechunk(&self) -> Series {
192
self.0.rechunk().into_owned().into_series()
193
}
194
195
fn new_from_index(&self, index: usize, length: usize) -> Series {
196
ChunkExpandAtIndex::new_from_index(&self.0, index, length).into_series()
197
}
198
199
fn trim_lists_to_normalized_offsets(&self) -> Option<Series> {
200
self.0
201
.trim_lists_to_normalized_offsets()
202
.map(IntoSeries::into_series)
203
}
204
205
fn propagate_nulls(&self) -> Option<Series> {
206
self.0.propagate_nulls().map(IntoSeries::into_series)
207
}
208
209
fn cast(&self, dtype: &DataType, options: CastOptions) -> PolarsResult<Series> {
210
self.0.cast_with_options(dtype, options)
211
}
212
213
#[inline]
214
unsafe fn get_unchecked(&self, index: usize) -> AnyValue<'_> {
215
self.0.get_any_value_unchecked(index)
216
}
217
218
fn null_count(&self) -> usize {
219
self.0.null_count()
220
}
221
222
fn has_nulls(&self) -> bool {
223
self.0.has_nulls()
224
}
225
226
fn is_null(&self) -> BooleanChunked {
227
self.0.is_null()
228
}
229
230
fn is_not_null(&self) -> BooleanChunked {
231
self.0.is_not_null()
232
}
233
234
fn reverse(&self) -> Series {
235
ChunkReverse::reverse(&self.0).into_series()
236
}
237
238
fn as_single_ptr(&mut self) -> PolarsResult<usize> {
239
self.0.as_single_ptr()
240
}
241
242
fn shift(&self, periods: i64) -> Series {
243
ChunkShift::shift(&self.0, periods).into_series()
244
}
245
246
fn clone_inner(&self) -> Arc<dyn SeriesTrait> {
247
Arc::new(SeriesWrap(Clone::clone(&self.0)))
248
}
249
250
fn find_validity_mismatch(&self, other: &Series, idxs: &mut Vec<IdxSize>) {
251
self.0.find_validity_mismatch(other, idxs)
252
}
253
254
fn as_any(&self) -> &dyn Any {
255
&self.0
256
}
257
258
fn as_any_mut(&mut self) -> &mut dyn Any {
259
&mut self.0
260
}
261
262
fn as_phys_any(&self) -> &dyn Any {
263
&self.0
264
}
265
266
fn as_arc_any(self: Arc<Self>) -> Arc<dyn Any + Send + Sync> {
267
self as _
268
}
269
}
270
271