Path: blob/main/crates/polars-core/src/series/implementations/string.rs
6940 views
use super::*;1use crate::chunked_array::comparison::*;2#[cfg(feature = "algorithm_group_by")]3use crate::frame::group_by::*;4use crate::prelude::*;56impl private::PrivateSeries for SeriesWrap<StringChunked> {7fn compute_len(&mut self) {8self.0.compute_len()9}10fn _field(&self) -> Cow<'_, Field> {11Cow::Borrowed(self.0.ref_field())12}13fn _dtype(&self) -> &DataType {14self.0.ref_field().dtype()15}1617fn _set_flags(&mut self, flags: StatisticsFlags) {18self.0.set_flags(flags)19}20fn _get_flags(&self) -> StatisticsFlags {21self.0.get_flags()22}23unsafe fn equal_element(&self, idx_self: usize, idx_other: usize, other: &Series) -> bool {24self.0.equal_element(idx_self, idx_other, other)25}2627#[cfg(feature = "zip_with")]28fn zip_with_same_type(&self, mask: &BooleanChunked, other: &Series) -> PolarsResult<Series> {29ChunkZip::zip_with(&self.0, mask, other.as_ref().as_ref()).map(|ca| ca.into_series())30}31fn into_total_eq_inner<'a>(&'a self) -> Box<dyn TotalEqInner + 'a> {32(&self.0).into_total_eq_inner()33}34fn into_total_ord_inner<'a>(&'a self) -> Box<dyn TotalOrdInner + 'a> {35(&self.0).into_total_ord_inner()36}3738fn vec_hash(39&self,40random_state: PlSeedableRandomStateQuality,41buf: &mut Vec<u64>,42) -> PolarsResult<()> {43self.0.vec_hash(random_state, buf)?;44Ok(())45}4647fn vec_hash_combine(48&self,49build_hasher: PlSeedableRandomStateQuality,50hashes: &mut [u64],51) -> PolarsResult<()> {52self.0.vec_hash_combine(build_hasher, hashes)?;53Ok(())54}5556#[cfg(feature = "algorithm_group_by")]57unsafe fn agg_list(&self, groups: &GroupsType) -> Series {58self.0.agg_list(groups)59}6061#[cfg(feature = "algorithm_group_by")]62unsafe fn agg_min(&self, groups: &GroupsType) -> Series {63self.0.agg_min(groups)64}6566#[cfg(feature = "algorithm_group_by")]67unsafe fn agg_max(&self, groups: &GroupsType) -> Series {68self.0.agg_max(groups)69}7071fn subtract(&self, rhs: &Series) -> PolarsResult<Series> {72NumOpsDispatch::subtract(&self.0, rhs)73}74fn add_to(&self, rhs: &Series) -> PolarsResult<Series> {75NumOpsDispatch::add_to(&self.0, rhs)76}77fn multiply(&self, rhs: &Series) -> PolarsResult<Series> {78NumOpsDispatch::multiply(&self.0, rhs)79}80fn divide(&self, rhs: &Series) -> PolarsResult<Series> {81NumOpsDispatch::divide(&self.0, rhs)82}83fn remainder(&self, rhs: &Series) -> PolarsResult<Series> {84NumOpsDispatch::remainder(&self.0, rhs)85}86#[cfg(feature = "algorithm_group_by")]87fn group_tuples(&self, multithreaded: bool, sorted: bool) -> PolarsResult<GroupsType> {88IntoGroupsType::group_tuples(&self.0, multithreaded, sorted)89}9091fn arg_sort_multiple(92&self,93by: &[Column],94options: &SortMultipleOptions,95) -> PolarsResult<IdxCa> {96self.0.arg_sort_multiple(by, options)97}98}99100impl SeriesTrait for SeriesWrap<StringChunked> {101fn rename(&mut self, name: PlSmallStr) {102self.0.rename(name);103}104105fn chunk_lengths(&self) -> ChunkLenIter<'_> {106self.0.chunk_lengths()107}108fn name(&self) -> &PlSmallStr {109self.0.name()110}111112fn chunks(&self) -> &Vec<ArrayRef> {113self.0.chunks()114}115unsafe fn chunks_mut(&mut self) -> &mut Vec<ArrayRef> {116self.0.chunks_mut()117}118fn shrink_to_fit(&mut self) {119self.0.shrink_to_fit()120}121122fn slice(&self, offset: i64, length: usize) -> Series {123self.0.slice(offset, length).into_series()124}125fn split_at(&self, offset: i64) -> (Series, Series) {126let (a, b) = self.0.split_at(offset);127(a.into_series(), b.into_series())128}129130fn append(&mut self, other: &Series) -> PolarsResult<()> {131polars_ensure!(self.0.dtype() == other.dtype(), append);132// todo! add object133self.0.append(other.as_ref().as_ref())?;134Ok(())135}136fn append_owned(&mut self, other: Series) -> PolarsResult<()> {137polars_ensure!(self.0.dtype() == other.dtype(), append);138// todo! add object139self.0.append_owned(other.take_inner())140}141142fn extend(&mut self, other: &Series) -> PolarsResult<()> {143polars_ensure!(144self.0.dtype() == other.dtype(),145SchemaMismatch: "cannot extend Series: data types don't match",146);147self.0.extend(other.as_ref().as_ref())?;148Ok(())149}150151fn filter(&self, filter: &BooleanChunked) -> PolarsResult<Series> {152ChunkFilter::filter(&self.0, filter).map(|ca| ca.into_series())153}154155fn take(&self, indices: &IdxCa) -> PolarsResult<Series> {156Ok(self.0.take(indices)?.into_series())157}158159unsafe fn take_unchecked(&self, indices: &IdxCa) -> Series {160self.0.take_unchecked(indices).into_series()161}162163fn take_slice(&self, indices: &[IdxSize]) -> PolarsResult<Series> {164Ok(self.0.take(indices)?.into_series())165}166167unsafe fn take_slice_unchecked(&self, indices: &[IdxSize]) -> Series {168self.0.take_unchecked(indices).into_series()169}170171fn len(&self) -> usize {172self.0.len()173}174175fn rechunk(&self) -> Series {176self.0.rechunk().into_owned().into_series()177}178179fn new_from_index(&self, index: usize, length: usize) -> Series {180ChunkExpandAtIndex::new_from_index(&self.0, index, length).into_series()181}182183fn cast(&self, dtype: &DataType, cast_options: CastOptions) -> PolarsResult<Series> {184self.0.cast_with_options(dtype, cast_options)185}186187#[inline]188unsafe fn get_unchecked(&self, index: usize) -> AnyValue<'_> {189self.0.get_any_value_unchecked(index)190}191192fn sort_with(&self, options: SortOptions) -> PolarsResult<Series> {193Ok(ChunkSort::sort_with(&self.0, options).into_series())194}195196fn arg_sort(&self, options: SortOptions) -> IdxCa {197ChunkSort::arg_sort(&self.0, options)198}199200fn null_count(&self) -> usize {201self.0.null_count()202}203204fn has_nulls(&self) -> bool {205self.0.has_nulls()206}207208#[cfg(feature = "algorithm_group_by")]209fn unique(&self) -> PolarsResult<Series> {210ChunkUnique::unique(&self.0).map(|ca| ca.into_series())211}212213#[cfg(feature = "algorithm_group_by")]214fn n_unique(&self) -> PolarsResult<usize> {215ChunkUnique::n_unique(&self.0)216}217218#[cfg(feature = "algorithm_group_by")]219fn arg_unique(&self) -> PolarsResult<IdxCa> {220ChunkUnique::arg_unique(&self.0)221}222223fn is_null(&self) -> BooleanChunked {224self.0.is_null()225}226227fn is_not_null(&self) -> BooleanChunked {228self.0.is_not_null()229}230231fn reverse(&self) -> Series {232ChunkReverse::reverse(&self.0).into_series()233}234235fn as_single_ptr(&mut self) -> PolarsResult<usize> {236self.0.as_single_ptr()237}238239fn shift(&self, periods: i64) -> Series {240ChunkShift::shift(&self.0, periods).into_series()241}242243fn sum_reduce(&self) -> PolarsResult<Scalar> {244Err(polars_err!(245op = "`sum`",246DataType::String,247hint = "you may mean to call `str.join` or `list.join`"248))249}250fn max_reduce(&self) -> PolarsResult<Scalar> {251Ok(ChunkAggSeries::max_reduce(&self.0))252}253fn min_reduce(&self) -> PolarsResult<Scalar> {254Ok(ChunkAggSeries::min_reduce(&self.0))255}256257#[cfg(feature = "approx_unique")]258fn approx_n_unique(&self) -> PolarsResult<IdxSize> {259Ok(ChunkApproxNUnique::approx_n_unique(&self.0))260}261262fn clone_inner(&self) -> Arc<dyn SeriesTrait> {263Arc::new(SeriesWrap(Clone::clone(&self.0)))264}265266fn find_validity_mismatch(&self, other: &Series, idxs: &mut Vec<IdxSize>) {267self.0.find_validity_mismatch(other, idxs)268}269270fn as_any(&self) -> &dyn Any {271&self.0272}273274fn as_any_mut(&mut self) -> &mut dyn Any {275&mut self.0276}277278fn as_phys_any(&self) -> &dyn Any {279&self.0280}281282fn as_arc_any(self: Arc<Self>) -> Arc<dyn Any + Send + Sync> {283self as _284}285}286287288