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/string.rs
8408 views
1
use super::*;
2
use crate::chunked_array::comparison::*;
3
#[cfg(feature = "algorithm_group_by")]
4
use crate::frame::group_by::*;
5
use crate::prelude::*;
6
7
impl private::PrivateSeries for SeriesWrap<StringChunked> {
8
fn compute_len(&mut self) {
9
self.0.compute_len()
10
}
11
fn _field(&self) -> Cow<'_, Field> {
12
Cow::Borrowed(self.0.ref_field())
13
}
14
fn _dtype(&self) -> &DataType {
15
self.0.ref_field().dtype()
16
}
17
18
fn _set_flags(&mut self, flags: StatisticsFlags) {
19
self.0.set_flags(flags)
20
}
21
fn _get_flags(&self) -> StatisticsFlags {
22
self.0.get_flags()
23
}
24
unsafe fn equal_element(&self, idx_self: usize, idx_other: usize, other: &Series) -> bool {
25
self.0.equal_element(idx_self, idx_other, other)
26
}
27
28
#[cfg(feature = "zip_with")]
29
fn zip_with_same_type(&self, mask: &BooleanChunked, other: &Series) -> PolarsResult<Series> {
30
ChunkZip::zip_with(&self.0, mask, other.as_ref().as_ref()).map(|ca| ca.into_series())
31
}
32
fn into_total_eq_inner<'a>(&'a self) -> Box<dyn TotalEqInner + 'a> {
33
(&self.0).into_total_eq_inner()
34
}
35
fn into_total_ord_inner<'a>(&'a self) -> Box<dyn TotalOrdInner + 'a> {
36
(&self.0).into_total_ord_inner()
37
}
38
39
fn vec_hash(
40
&self,
41
random_state: PlSeedableRandomStateQuality,
42
buf: &mut Vec<u64>,
43
) -> PolarsResult<()> {
44
self.0.vec_hash(random_state, buf)?;
45
Ok(())
46
}
47
48
fn vec_hash_combine(
49
&self,
50
build_hasher: PlSeedableRandomStateQuality,
51
hashes: &mut [u64],
52
) -> PolarsResult<()> {
53
self.0.vec_hash_combine(build_hasher, hashes)?;
54
Ok(())
55
}
56
57
#[cfg(feature = "algorithm_group_by")]
58
unsafe fn agg_list(&self, groups: &GroupsType) -> Series {
59
self.0.agg_list(groups)
60
}
61
62
#[cfg(feature = "algorithm_group_by")]
63
unsafe fn agg_min(&self, groups: &GroupsType) -> Series {
64
self.0.agg_min(groups)
65
}
66
67
#[cfg(feature = "algorithm_group_by")]
68
unsafe fn agg_max(&self, groups: &GroupsType) -> Series {
69
self.0.agg_max(groups)
70
}
71
72
#[cfg(feature = "algorithm_group_by")]
73
unsafe fn agg_arg_min(&self, groups: &GroupsType) -> Series {
74
self.0.agg_arg_min(groups)
75
}
76
77
#[cfg(feature = "algorithm_group_by")]
78
unsafe fn agg_arg_max(&self, groups: &GroupsType) -> Series {
79
self.0.agg_arg_max(groups)
80
}
81
82
fn subtract(&self, rhs: &Series) -> PolarsResult<Series> {
83
NumOpsDispatch::subtract(&self.0, rhs)
84
}
85
fn add_to(&self, rhs: &Series) -> PolarsResult<Series> {
86
NumOpsDispatch::add_to(&self.0, rhs)
87
}
88
fn multiply(&self, rhs: &Series) -> PolarsResult<Series> {
89
NumOpsDispatch::multiply(&self.0, rhs)
90
}
91
fn divide(&self, rhs: &Series) -> PolarsResult<Series> {
92
NumOpsDispatch::divide(&self.0, rhs)
93
}
94
fn remainder(&self, rhs: &Series) -> PolarsResult<Series> {
95
NumOpsDispatch::remainder(&self.0, rhs)
96
}
97
#[cfg(feature = "algorithm_group_by")]
98
fn group_tuples(&self, multithreaded: bool, sorted: bool) -> PolarsResult<GroupsType> {
99
IntoGroupsType::group_tuples(&self.0, multithreaded, sorted)
100
}
101
102
fn arg_sort_multiple(
103
&self,
104
by: &[Column],
105
options: &SortMultipleOptions,
106
) -> PolarsResult<IdxCa> {
107
self.0.arg_sort_multiple(by, options)
108
}
109
}
110
111
impl SeriesTrait for SeriesWrap<StringChunked> {
112
fn rename(&mut self, name: PlSmallStr) {
113
self.0.rename(name);
114
}
115
116
fn chunk_lengths(&self) -> ChunkLenIter<'_> {
117
self.0.chunk_lengths()
118
}
119
fn name(&self) -> &PlSmallStr {
120
self.0.name()
121
}
122
123
fn chunks(&self) -> &Vec<ArrayRef> {
124
self.0.chunks()
125
}
126
unsafe fn chunks_mut(&mut self) -> &mut Vec<ArrayRef> {
127
self.0.chunks_mut()
128
}
129
fn shrink_to_fit(&mut self) {
130
self.0.shrink_to_fit()
131
}
132
133
fn slice(&self, offset: i64, length: usize) -> Series {
134
self.0.slice(offset, length).into_series()
135
}
136
fn split_at(&self, offset: i64) -> (Series, Series) {
137
let (a, b) = self.0.split_at(offset);
138
(a.into_series(), b.into_series())
139
}
140
141
fn append(&mut self, other: &Series) -> PolarsResult<()> {
142
polars_ensure!(self.0.dtype() == other.dtype(), append);
143
// todo! add object
144
self.0.append(other.as_ref().as_ref())?;
145
Ok(())
146
}
147
fn append_owned(&mut self, other: Series) -> PolarsResult<()> {
148
polars_ensure!(self.0.dtype() == other.dtype(), append);
149
// todo! add object
150
self.0.append_owned(other.take_inner())
151
}
152
153
fn extend(&mut self, other: &Series) -> PolarsResult<()> {
154
polars_ensure!(
155
self.0.dtype() == other.dtype(),
156
SchemaMismatch: "cannot extend Series: data types don't match",
157
);
158
self.0.extend(other.as_ref().as_ref())?;
159
Ok(())
160
}
161
162
fn filter(&self, filter: &BooleanChunked) -> PolarsResult<Series> {
163
ChunkFilter::filter(&self.0, filter).map(|ca| ca.into_series())
164
}
165
166
fn take(&self, indices: &IdxCa) -> PolarsResult<Series> {
167
Ok(self.0.take(indices)?.into_series())
168
}
169
170
unsafe fn take_unchecked(&self, indices: &IdxCa) -> Series {
171
self.0.take_unchecked(indices).into_series()
172
}
173
174
fn take_slice(&self, indices: &[IdxSize]) -> PolarsResult<Series> {
175
Ok(self.0.take(indices)?.into_series())
176
}
177
178
unsafe fn take_slice_unchecked(&self, indices: &[IdxSize]) -> Series {
179
self.0.take_unchecked(indices).into_series()
180
}
181
182
fn deposit(&self, validity: &Bitmap) -> Series {
183
self.0.deposit(validity).into_series()
184
}
185
186
fn len(&self) -> usize {
187
self.0.len()
188
}
189
190
fn rechunk(&self) -> Series {
191
self.0.rechunk().into_owned().into_series()
192
}
193
194
fn new_from_index(&self, index: usize, length: usize) -> Series {
195
ChunkExpandAtIndex::new_from_index(&self.0, index, length).into_series()
196
}
197
198
fn cast(&self, dtype: &DataType, cast_options: CastOptions) -> PolarsResult<Series> {
199
self.0.cast_with_options(dtype, cast_options)
200
}
201
202
#[inline]
203
unsafe fn get_unchecked(&self, index: usize) -> AnyValue<'_> {
204
self.0.get_any_value_unchecked(index)
205
}
206
207
fn sort_with(&self, options: SortOptions) -> PolarsResult<Series> {
208
Ok(ChunkSort::sort_with(&self.0, options).into_series())
209
}
210
211
fn arg_sort(&self, options: SortOptions) -> IdxCa {
212
ChunkSort::arg_sort(&self.0, options)
213
}
214
215
fn null_count(&self) -> usize {
216
self.0.null_count()
217
}
218
219
fn has_nulls(&self) -> bool {
220
self.0.has_nulls()
221
}
222
223
#[cfg(feature = "algorithm_group_by")]
224
fn unique(&self) -> PolarsResult<Series> {
225
ChunkUnique::unique(&self.0).map(|ca| ca.into_series())
226
}
227
228
#[cfg(feature = "algorithm_group_by")]
229
fn n_unique(&self) -> PolarsResult<usize> {
230
ChunkUnique::n_unique(&self.0)
231
}
232
233
#[cfg(feature = "algorithm_group_by")]
234
fn arg_unique(&self) -> PolarsResult<IdxCa> {
235
ChunkUnique::arg_unique(&self.0)
236
}
237
238
fn unique_id(&self) -> PolarsResult<(IdxSize, Vec<IdxSize>)> {
239
ChunkUnique::unique_id(&self.0)
240
}
241
242
fn is_null(&self) -> BooleanChunked {
243
self.0.is_null()
244
}
245
246
fn is_not_null(&self) -> BooleanChunked {
247
self.0.is_not_null()
248
}
249
250
fn reverse(&self) -> Series {
251
ChunkReverse::reverse(&self.0).into_series()
252
}
253
254
fn as_single_ptr(&mut self) -> PolarsResult<usize> {
255
self.0.as_single_ptr()
256
}
257
258
fn shift(&self, periods: i64) -> Series {
259
ChunkShift::shift(&self.0, periods).into_series()
260
}
261
262
fn sum_reduce(&self) -> PolarsResult<Scalar> {
263
Err(polars_err!(
264
op = "`sum`",
265
DataType::String,
266
hint = "you may mean to call `str.join` or `list.join`"
267
))
268
}
269
fn max_reduce(&self) -> PolarsResult<Scalar> {
270
Ok(ChunkAggSeries::max_reduce(&self.0))
271
}
272
fn min_reduce(&self) -> PolarsResult<Scalar> {
273
Ok(ChunkAggSeries::min_reduce(&self.0))
274
}
275
276
#[cfg(feature = "approx_unique")]
277
fn approx_n_unique(&self) -> PolarsResult<IdxSize> {
278
Ok(ChunkApproxNUnique::approx_n_unique(&self.0))
279
}
280
281
fn clone_inner(&self) -> Arc<dyn SeriesTrait> {
282
Arc::new(SeriesWrap(Clone::clone(&self.0)))
283
}
284
285
fn find_validity_mismatch(&self, other: &Series, idxs: &mut Vec<IdxSize>) {
286
self.0.find_validity_mismatch(other, idxs)
287
}
288
289
fn as_any(&self) -> &dyn Any {
290
&self.0
291
}
292
293
fn as_any_mut(&mut self) -> &mut dyn Any {
294
&mut self.0
295
}
296
297
fn as_phys_any(&self) -> &dyn Any {
298
&self.0
299
}
300
301
fn as_arc_any(self: Arc<Self>) -> Arc<dyn Any + Send + Sync> {
302
self as _
303
}
304
}
305
306