polars_core/series/implementations/
array.rs

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