Trait polars::series::SeriesTrait
source · [−]pub trait SeriesTrait: Send + Sync + PrivateSeries + PrivateSeriesNumeric {
Show 72 methods
fn interpolate(&self) -> Series;
fn rename(&mut self, name: &str);
fn chunks(&self) -> &Vec<Box<dyn Array + 'static, Global>, Global>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A>where
A: Allocator,
;
fn take_iter(
&self,
_iter: &mut dyn TakeIterator<Item = usize>
) -> Result<Series, PolarsError>;
unsafe fn take_iter_unchecked(
&self,
_iter: &mut dyn TakeIterator<Item = usize>
) -> Series;
unsafe fn take_unchecked(
&self,
_idx: &ChunkedArray<UInt32Type>
) -> Result<Series, PolarsError>;
unsafe fn take_opt_iter_unchecked(
&self,
_iter: &mut dyn TakeIteratorNulls<Item = Option<usize>>
) -> Series;
fn take(
&self,
_indices: &ChunkedArray<UInt32Type>
) -> Result<Series, PolarsError>;
fn len(&self) -> usize;
fn take_every(&self, n: usize) -> Series;
fn has_validity(&self) -> bool;
fn is_sorted(&self) -> IsSorted { ... }
fn bitand(&self, _other: &Series) -> Result<Series, PolarsError> { ... }
fn bitor(&self, _other: &Series) -> Result<Series, PolarsError> { ... }
fn bitxor(&self, _other: &Series) -> Result<Series, PolarsError> { ... }
fn chunk_lengths(
&self
) -> Map<Iter<'_, Box<dyn Array + 'static, Global>>, fn(&Box<dyn Array + 'static, Global>) -> usize> { ... }
fn name(&self) -> &str { ... }
fn field(&self) -> Cow<'_, Field> { ... }
fn dtype(&self) -> &DataType { ... }
fn n_chunks(&self) -> usize { ... }
fn shrink_to_fit(&mut self) { ... }
fn append_array(
&mut self,
_other: Box<dyn Array + 'static, Global>
) -> Result<(), PolarsError> { ... }
fn limit(&self, num_elements: usize) -> Series { ... }
fn slice(&self, _offset: i64, _length: usize) -> Series { ... }
fn filter(
&self,
_filter: &ChunkedArray<BooleanType>
) -> Result<Series, PolarsError> { ... }
fn take_opt_iter(
&self,
_iter: &mut dyn TakeIteratorNulls<Item = Option<usize>>
) -> Result<Series, PolarsError> { ... }
fn is_empty(&self) -> bool { ... }
fn rechunk(&self) -> Series { ... }
fn drop_nulls(&self) -> Series { ... }
fn mean(&self) -> Option<f64> { ... }
fn median(&self) -> Option<f64> { ... }
fn expand_at_index(&self, _index: usize, _length: usize) -> Series { ... }
fn cast(&self, _data_type: &DataType) -> Result<Series, PolarsError> { ... }
fn get(&self, _index: usize) -> AnyValue<'_> { ... }
unsafe fn get_unchecked(&self, _index: usize) -> AnyValue<'_> { ... }
fn sort_with(&self, _options: SortOptions) -> Series { ... }
fn argsort(&self, options: SortOptions) -> ChunkedArray<UInt32Type> { ... }
fn null_count(&self) -> usize { ... }
fn unique(&self) -> Result<Series, PolarsError> { ... }
fn n_unique(&self) -> Result<usize, PolarsError> { ... }
fn arg_unique(&self) -> Result<ChunkedArray<UInt32Type>, PolarsError> { ... }
fn arg_min(&self) -> Option<usize> { ... }
fn arg_max(&self) -> Option<usize> { ... }
fn is_null(&self) -> ChunkedArray<BooleanType> { ... }
fn is_not_null(&self) -> ChunkedArray<BooleanType> { ... }
fn is_unique(&self) -> Result<ChunkedArray<BooleanType>, PolarsError> { ... }
fn is_duplicated(&self) -> Result<ChunkedArray<BooleanType>, PolarsError> { ... }
fn reverse(&self) -> Series { ... }
fn as_single_ptr(&mut self) -> Result<usize, PolarsError> { ... }
fn shift(&self, _periods: i64) -> Series { ... }
fn fill_null(
&self,
_strategy: FillNullStrategy
) -> Result<Series, PolarsError> { ... }
fn _sum_as_series(&self) -> Series { ... }
fn max_as_series(&self) -> Series { ... }
fn min_as_series(&self) -> Series { ... }
fn median_as_series(&self) -> Series { ... }
fn var_as_series(&self, _ddof: u8) -> Series { ... }
fn std_as_series(&self, _ddof: u8) -> Series { ... }
fn quantile_as_series(
&self,
_quantile: f64,
_interpol: QuantileInterpolOptions
) -> Result<Series, PolarsError> { ... }
fn fmt_list(&self) -> String { ... }
fn clone_inner(&self) -> Arc<dyn SeriesTrait + 'static> { ... }
fn get_object(
&self,
_index: usize
) -> Option<&(dyn PolarsObjectSafe + 'static)> { ... }
fn as_any(&self) -> &(dyn Any + 'static) { ... }
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static) { ... }
fn peak_max(&self) -> ChunkedArray<BooleanType> { ... }
fn peak_min(&self) -> ChunkedArray<BooleanType> { ... }
fn is_in(
&self,
_other: &Series
) -> Result<ChunkedArray<BooleanType>, PolarsError> { ... }
fn repeat_by(&self, _by: &ChunkedArray<UInt32Type>) -> ChunkedArray<ListType> { ... }
fn checked_div(&self, _rhs: &Series) -> Result<Series, PolarsError> { ... }
fn is_first(&self) -> Result<ChunkedArray<BooleanType>, PolarsError> { ... }
fn mode(&self) -> Result<Series, PolarsError> { ... }
fn rolling_apply(
&self,
_f: &dyn Fn(&Series),
_options: RollingOptionsFixedWindow
) -> Result<Series, PolarsError> { ... }
fn str_concat(&self, _delimiter: &str) -> ChunkedArray<Utf8Type> { ... }
}
Required Methods
fn interpolate(&self) -> Series
Underlying chunks.
sourcefn take_iter(
&self,
_iter: &mut dyn TakeIterator<Item = usize>
) -> Result<Series, PolarsError>
fn take_iter(
&self,
_iter: &mut dyn TakeIterator<Item = usize>
) -> Result<Series, PolarsError>
Take by index from an iterator. This operation clones the data.
sourceunsafe fn take_iter_unchecked(
&self,
_iter: &mut dyn TakeIterator<Item = usize>
) -> Series
unsafe fn take_iter_unchecked(
&self,
_iter: &mut dyn TakeIterator<Item = usize>
) -> Series
Take by index from an iterator. This operation clones the data.
Safety
- This doesn’t check any bounds.
- Iterator must be TrustedLen
sourceunsafe fn take_unchecked(
&self,
_idx: &ChunkedArray<UInt32Type>
) -> Result<Series, PolarsError>
unsafe fn take_unchecked(
&self,
_idx: &ChunkedArray<UInt32Type>
) -> Result<Series, PolarsError>
sourceunsafe fn take_opt_iter_unchecked(
&self,
_iter: &mut dyn TakeIteratorNulls<Item = Option<usize>>
) -> Series
unsafe fn take_opt_iter_unchecked(
&self,
_iter: &mut dyn TakeIteratorNulls<Item = Option<usize>>
) -> Series
Take by index from an iterator. This operation clones the data.
Safety
- This doesn’t check any bounds.
- Iterator must be TrustedLen
sourcefn take(
&self,
_indices: &ChunkedArray<UInt32Type>
) -> Result<Series, PolarsError>
fn take(
&self,
_indices: &ChunkedArray<UInt32Type>
) -> Result<Series, PolarsError>
Take by index. This operation is clone.
sourcefn take_every(&self, n: usize) -> Series
fn take_every(&self, n: usize) -> Series
Take every nth value as a new Series
sourcefn has_validity(&self) -> bool
fn has_validity(&self) -> bool
Return if any the chunks in this [ChunkedArray]
have a validity bitmap.
no bitmap means no null values.
Provided Methods
Get the lengths of the underlying chunks
sourcefn shrink_to_fit(&mut self)
fn shrink_to_fit(&mut self)
Shrink the capacity of this array to fit its length.
sourcefn append_array(
&mut self,
_other: Box<dyn Array + 'static, Global>
) -> Result<(), PolarsError>
fn append_array(
&mut self,
_other: Box<dyn Array + 'static, Global>
) -> Result<(), PolarsError>
Append Arrow array of same dtype to this Series.
Take num_elements
from the top as a zero copy view.
Get a zero copy view of the data.
When offset is negative the offset is counted from the end of the array
sourcefn filter(
&self,
_filter: &ChunkedArray<BooleanType>
) -> Result<Series, PolarsError>
fn filter(
&self,
_filter: &ChunkedArray<BooleanType>
) -> Result<Series, PolarsError>
Filter by boolean mask. This operation clones data.
sourcefn take_opt_iter(
&self,
_iter: &mut dyn TakeIteratorNulls<Item = Option<usize>>
) -> Result<Series, PolarsError>
fn take_opt_iter(
&self,
_iter: &mut dyn TakeIteratorNulls<Item = Option<usize>>
) -> Result<Series, PolarsError>
Take by index from an iterator. This operation clones the data. todo! remove?
sourcefn drop_nulls(&self) -> Series
fn drop_nulls(&self) -> Series
Drop all null values and return a new Series.
Returns the mean value in the array Returns an option because the array is nullable.
Returns the median value in the array Returns an option because the array is nullable.
sourcefn expand_at_index(&self, _index: usize, _length: usize) -> Series
fn expand_at_index(&self, _index: usize, _length: usize) -> Series
Create a new Series filled with values at that index.
Example
use polars_core::prelude::*;
let s = Series::new("a", [0i32, 1, 8]);
let expanded = s.expand_at_index(2, 4);
assert_eq!(Vec::from(expanded.i32().unwrap()), &[Some(8), Some(8), Some(8), Some(8)])
Get a single value by index. Don’t use this operation for loops as a runtime cast is needed for every iteration.
sourceunsafe fn get_unchecked(&self, _index: usize) -> AnyValue<'_>
unsafe fn get_unchecked(&self, _index: usize) -> AnyValue<'_>
Get a single value by index. Don’t use this operation for loops as a runtime cast is needed for every iteration.
This may refer to physical types
Safety
Does not do any bounds checking
fn sort_with(&self, _options: SortOptions) -> Series
sourcefn argsort(&self, options: SortOptions) -> ChunkedArray<UInt32Type>
fn argsort(&self, options: SortOptions) -> ChunkedArray<UInt32Type>
Retrieve the indexes needed for a sort.
sourcefn null_count(&self) -> usize
fn null_count(&self) -> usize
Count the null values.
sourcefn unique(&self) -> Result<Series, PolarsError>
fn unique(&self) -> Result<Series, PolarsError>
Get unique values in the Series.
sourcefn n_unique(&self) -> Result<usize, PolarsError>
fn n_unique(&self) -> Result<usize, PolarsError>
Get unique values in the Series.
sourcefn arg_unique(&self) -> Result<ChunkedArray<UInt32Type>, PolarsError>
fn arg_unique(&self) -> Result<ChunkedArray<UInt32Type>, PolarsError>
Get first indexes of unique values.
sourcefn is_null(&self) -> ChunkedArray<BooleanType>
fn is_null(&self) -> ChunkedArray<BooleanType>
Get a mask of the null values.
sourcefn is_not_null(&self) -> ChunkedArray<BooleanType>
fn is_not_null(&self) -> ChunkedArray<BooleanType>
Get a mask of the non-null values.
sourcefn is_unique(&self) -> Result<ChunkedArray<BooleanType>, PolarsError>
fn is_unique(&self) -> Result<ChunkedArray<BooleanType>, PolarsError>
Get a mask of all the unique values.
sourcefn is_duplicated(&self) -> Result<ChunkedArray<BooleanType>, PolarsError>
fn is_duplicated(&self) -> Result<ChunkedArray<BooleanType>, PolarsError>
Get a mask of all the duplicated values.
sourcefn as_single_ptr(&mut self) -> Result<usize, PolarsError>
fn as_single_ptr(&mut self) -> Result<usize, PolarsError>
Rechunk and return a pointer to the start of the Series. Only implemented for numeric types
Shift the values by a given period and fill the parts that will be empty due to this operation
with Nones
.
NOTE: If you want to fill the Nones with a value use the
shift
operation on ChunkedArray<T>
.
Example
fn example() -> PolarsResult<()> {
let s = Series::new("series", &[1, 2, 3]);
let shifted = s.shift(1);
assert_eq!(Vec::from(shifted.i32()?), &[None, Some(1), Some(2)]);
let shifted = s.shift(-1);
assert_eq!(Vec::from(shifted.i32()?), &[Some(2), Some(3), None]);
let shifted = s.shift(2);
assert_eq!(Vec::from(shifted.i32()?), &[None, None, Some(1)]);
Ok(())
}
example();
sourcefn fill_null(&self, _strategy: FillNullStrategy) -> Result<Series, PolarsError>
fn fill_null(&self, _strategy: FillNullStrategy) -> Result<Series, PolarsError>
Replace None values with one of the following strategies:
- Forward fill (replace None with the previous value)
- Backward fill (replace None with the next value)
- Mean fill (replace None with the mean of the whole array)
- Min fill (replace None with the minimum of the whole array)
- Max fill (replace None with the maximum of the whole array)
NOTE: If you want to fill the Nones with a value use the
fill_null
operation on ChunkedArray<T>
.
Example
fn example() -> PolarsResult<()> {
let s = Series::new("some_missing", &[Some(1), None, Some(2)]);
let filled = s.fill_null(FillNullStrategy::Forward(None))?;
assert_eq!(Vec::from(filled.i32()?), &[Some(1), Some(1), Some(2)]);
let filled = s.fill_null(FillNullStrategy::Backward(None))?;
assert_eq!(Vec::from(filled.i32()?), &[Some(1), Some(2), Some(2)]);
let filled = s.fill_null(FillNullStrategy::Min)?;
assert_eq!(Vec::from(filled.i32()?), &[Some(1), Some(1), Some(2)]);
let filled = s.fill_null(FillNullStrategy::Max)?;
assert_eq!(Vec::from(filled.i32()?), &[Some(1), Some(2), Some(2)]);
let filled = s.fill_null(FillNullStrategy::Mean)?;
assert_eq!(Vec::from(filled.i32()?), &[Some(1), Some(1), Some(2)]);
Ok(())
}
example();
sourcefn _sum_as_series(&self) -> Series
fn _sum_as_series(&self) -> Series
Get the sum of the Series as a new Series of length 1.
If the DataType
is one of {Int8, UInt8, Int16, UInt16}
the Series
is
first cast to Int64
to prevent overflow issues.
sourcefn max_as_series(&self) -> Series
fn max_as_series(&self) -> Series
Get the max of the Series as a new Series of length 1.
sourcefn min_as_series(&self) -> Series
fn min_as_series(&self) -> Series
Get the min of the Series as a new Series of length 1.
sourcefn median_as_series(&self) -> Series
fn median_as_series(&self) -> Series
Get the median of the Series as a new Series of length 1.
sourcefn var_as_series(&self, _ddof: u8) -> Series
fn var_as_series(&self, _ddof: u8) -> Series
Get the variance of the Series as a new Series of length 1.
sourcefn std_as_series(&self, _ddof: u8) -> Series
fn std_as_series(&self, _ddof: u8) -> Series
Get the standard deviation of the Series as a new Series of length 1.
sourcefn quantile_as_series(
&self,
_quantile: f64,
_interpol: QuantileInterpolOptions
) -> Result<Series, PolarsError>
fn quantile_as_series(
&self,
_quantile: f64,
_interpol: QuantileInterpolOptions
) -> Result<Series, PolarsError>
Get the quantile of the ChunkedArray as a new Series of length 1.
sourcefn clone_inner(&self) -> Arc<dyn SeriesTrait + 'static>
fn clone_inner(&self) -> Arc<dyn SeriesTrait + 'static>
Clone inner ChunkedArray and wrap in a new Arc
sourcefn get_object(&self, _index: usize) -> Option<&(dyn PolarsObjectSafe + 'static)>
fn get_object(&self, _index: usize) -> Option<&(dyn PolarsObjectSafe + 'static)>
Get the value at this index as a downcastable Any trait ref.
Get a hold to self as Any
trait reference.
Only implemented for ObjectType
sourcefn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Get a hold to self as Any
trait reference.
Only implemented for ObjectType
sourcefn peak_max(&self) -> ChunkedArray<BooleanType>
fn peak_max(&self) -> ChunkedArray<BooleanType>
Get a boolean mask of the local maximum peaks.
sourcefn peak_min(&self) -> ChunkedArray<BooleanType>
fn peak_min(&self) -> ChunkedArray<BooleanType>
Get a boolean mask of the local minimum peaks.
sourcefn is_in(
&self,
_other: &Series
) -> Result<ChunkedArray<BooleanType>, PolarsError>
fn is_in(
&self,
_other: &Series
) -> Result<ChunkedArray<BooleanType>, PolarsError>
Check if elements of this Series are in the right Series, or List values of the right Series.
fn repeat_by(&self, _by: &ChunkedArray<UInt32Type>) -> ChunkedArray<ListType>
fn checked_div(&self, _rhs: &Series) -> Result<Series, PolarsError>
sourcefn is_first(&self) -> Result<ChunkedArray<BooleanType>, PolarsError>
fn is_first(&self) -> Result<ChunkedArray<BooleanType>, PolarsError>
Get a mask of the first unique values.
sourcefn mode(&self) -> Result<Series, PolarsError>
fn mode(&self) -> Result<Series, PolarsError>
Compute the most occurring element in the array.
sourcefn rolling_apply(
&self,
_f: &dyn Fn(&Series),
_options: RollingOptionsFixedWindow
) -> Result<Series, PolarsError>
fn rolling_apply(
&self,
_f: &dyn Fn(&Series),
_options: RollingOptionsFixedWindow
) -> Result<Series, PolarsError>
Apply a custom function over a rolling/ moving window of the array. This has quite some dynamic dispatch, so prefer rolling_min, max, mean, sum over this.
sourcefn str_concat(&self, _delimiter: &str) -> ChunkedArray<Utf8Type>
fn str_concat(&self, _delimiter: &str) -> ChunkedArray<Utf8Type>
Concat the values into a string array.
Arguments
delimiter
- A string that will act as delimiter between values.