Skip to main content

polars_core/series/implementations/
string.rs

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