Trait polars_core::series::SeriesTrait
source · [−]pub trait SeriesTrait: Send + Sync + PrivateSeries + PrivateSeriesNumeric {
Show 92 methods
fn interpolate(&self) -> Series;
fn rename(&mut self, name: &str);
fn take_every(&self, n: usize) -> Series;
fn has_validity(&self) -> bool;
fn is_sorted(&self) -> IsSorted { ... }
fn bitand(&self, _other: &Series) -> Result<Series> { ... }
fn bitor(&self, _other: &Series) -> Result<Series> { ... }
fn bitxor(&self, _other: &Series) -> Result<Series> { ... }
fn chunk_lengths(&self) -> ChunkIdIter<'_> { ... }
fn name(&self) -> &str { ... }
fn field(&self) -> Cow<'_, Field> { ... }
fn dtype(&self) -> &DataType { ... }
fn chunks(&self) -> &Vec<ArrayRef>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
{ ... }
fn n_chunks(&self) -> usize { ... }
fn shrink_to_fit(&mut self) { ... }
fn i8(&self) -> Result<&Int8Chunked> { ... }
fn i16(&self) -> Result<&Int16Chunked> { ... }
fn i32(&self) -> Result<&Int32Chunked> { ... }
fn i64(&self) -> Result<&Int64Chunked> { ... }
fn f32(&self) -> Result<&Float32Chunked> { ... }
fn f64(&self) -> Result<&Float64Chunked> { ... }
fn u8(&self) -> Result<&UInt8Chunked> { ... }
fn u16(&self) -> Result<&UInt16Chunked> { ... }
fn u32(&self) -> Result<&UInt32Chunked> { ... }
fn u64(&self) -> Result<&UInt64Chunked> { ... }
fn bool(&self) -> Result<&BooleanChunked> { ... }
fn utf8(&self) -> Result<&Utf8Chunked> { ... }
fn time(&self) -> Result<&TimeChunked> { ... }
fn date(&self) -> Result<&DateChunked> { ... }
fn datetime(&self) -> Result<&DatetimeChunked> { ... }
fn duration(&self) -> Result<&DurationChunked> { ... }
fn list(&self) -> Result<&ListChunked> { ... }
fn categorical(&self) -> Result<&CategoricalChunked> { ... }
fn append_array(&mut self, _other: ArrayRef) -> Result<()> { ... }
fn limit(&self, num_elements: usize) -> Series { ... }
fn slice(&self, _offset: i64, _length: usize) -> Series { ... }
fn filter(&self, _filter: &BooleanChunked) -> Result<Series> { ... }
fn take_iter(&self, _iter: &mut dyn TakeIterator) -> Result<Series> { ... }
unsafe fn take_iter_unchecked(&self, _iter: &mut dyn TakeIterator) -> Series { ... }
unsafe fn take_unchecked(&self, _idx: &IdxCa) -> Result<Series> { ... }
unsafe fn take_opt_iter_unchecked(
&self,
_iter: &mut dyn TakeIteratorNulls
) -> Series { ... }
fn take_opt_iter(&self, _iter: &mut dyn TakeIteratorNulls) -> Result<Series> { ... }
fn take(&self, _indices: &IdxCa) -> Result<Series> { ... }
fn len(&self) -> usize { ... }
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> { ... }
fn to_dummies(&self) -> Result<DataFrame> { ... }
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) -> IdxCa { ... }
fn null_count(&self) -> usize { ... }
fn unique(&self) -> Result<Series> { ... }
fn n_unique(&self) -> Result<usize> { ... }
fn arg_unique(&self) -> Result<IdxCa> { ... }
fn arg_min(&self) -> Option<usize> { ... }
fn arg_max(&self) -> Option<usize> { ... }
fn arg_true(&self) -> Result<IdxCa> { ... }
fn is_null(&self) -> BooleanChunked { ... }
fn is_not_null(&self) -> BooleanChunked { ... }
fn is_unique(&self) -> Result<BooleanChunked> { ... }
fn is_duplicated(&self) -> Result<BooleanChunked> { ... }
fn reverse(&self) -> Series { ... }
fn as_single_ptr(&mut self) -> Result<usize> { ... }
fn shift(&self, _periods: i64) -> Series { ... }
fn fill_null(&self, _strategy: FillNullStrategy) -> Result<Series> { ... }
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) -> Series { ... }
fn std_as_series(&self) -> Series { ... }
fn quantile_as_series(
&self,
_quantile: f64,
_interpol: QuantileInterpolOptions
) -> Result<Series> { ... }
fn fmt_list(&self) -> String { ... }
fn clone_inner(&self) -> Arc<dyn SeriesTrait> { ... }
fn get_object(&self, _index: usize) -> Option<&dyn PolarsObjectSafe> { ... }
fn as_any(&self) -> &dyn Any { ... }
fn pow(&self, _exponent: f64) -> Result<Series> { ... }
fn peak_max(&self) -> BooleanChunked { ... }
fn peak_min(&self) -> BooleanChunked { ... }
fn is_in(&self, _other: &Series) -> Result<BooleanChunked> { ... }
fn repeat_by(&self, _by: &IdxCa) -> ListChunked { ... }
fn checked_div(&self, _rhs: &Series) -> Result<Series> { ... }
fn is_first(&self) -> Result<BooleanChunked> { ... }
fn mode(&self) -> Result<Series> { ... }
fn rolling_apply(
&self,
_f: &dyn Fn(&Series) -> Series,
_options: RollingOptions
) -> Result<Series> { ... }
fn str_concat(&self, _delimiter: &str) -> Utf8Chunked { ... }
}
Required methods
fn interpolate(&self) -> Series
fn take_every(&self, n: usize) -> Series
fn take_every(&self, n: usize) -> Series
Take every nth value as a new Series
fn 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
fn chunk_lengths(&self) -> ChunkIdIter<'_>
fn chunk_lengths(&self) -> ChunkIdIter<'_>
Get the lengths of the underlying chunks
Underlying chunks.
fn shrink_to_fit(&mut self)
fn shrink_to_fit(&mut self)
Shrink the capacity of this array to fit it’s length.
fn i8(&self) -> Result<&Int8Chunked>
fn i8(&self) -> Result<&Int8Chunked>
Unpack to ChunkedArray of dtype i8
fn i16(&self) -> Result<&Int16Chunked>
fn i16(&self) -> Result<&Int16Chunked>
Unpack to ChunkedArray i16
fn i32(&self) -> Result<&Int32Chunked>
fn i32(&self) -> Result<&Int32Chunked>
Unpack to ChunkedArray
let s: Series = [1, 2, 3].iter().collect();
let s_squared: Series = s.i32()
.unwrap()
.into_iter()
.map(|opt_v| {
match opt_v {
Some(v) => Some(v * v),
None => None, // null value
}
}).collect();
fn i64(&self) -> Result<&Int64Chunked>
fn i64(&self) -> Result<&Int64Chunked>
Unpack to ChunkedArray of dtype i64
fn f32(&self) -> Result<&Float32Chunked>
fn f32(&self) -> Result<&Float32Chunked>
Unpack to ChunkedArray of dtype f32
fn f64(&self) -> Result<&Float64Chunked>
fn f64(&self) -> Result<&Float64Chunked>
Unpack to ChunkedArray of dtype f64
fn u8(&self) -> Result<&UInt8Chunked>
fn u8(&self) -> Result<&UInt8Chunked>
Unpack to ChunkedArray of dtype u8
fn u16(&self) -> Result<&UInt16Chunked>
fn u16(&self) -> Result<&UInt16Chunked>
Unpack to ChunkedArray of dtype u16
fn u32(&self) -> Result<&UInt32Chunked>
fn u32(&self) -> Result<&UInt32Chunked>
Unpack to ChunkedArray of dtype u32
fn u64(&self) -> Result<&UInt64Chunked>
fn u64(&self) -> Result<&UInt64Chunked>
Unpack to ChunkedArray of dtype u64
fn bool(&self) -> Result<&BooleanChunked>
fn bool(&self) -> Result<&BooleanChunked>
Unpack to ChunkedArray of dtype bool
fn utf8(&self) -> Result<&Utf8Chunked>
fn utf8(&self) -> Result<&Utf8Chunked>
Unpack to ChunkedArray of dtype utf8
fn time(&self) -> Result<&TimeChunked>
fn time(&self) -> Result<&TimeChunked>
Unpack to ChunkedArray of dtype Time
fn date(&self) -> Result<&DateChunked>
fn date(&self) -> Result<&DateChunked>
Unpack to ChunkedArray of dtype Date
fn datetime(&self) -> Result<&DatetimeChunked>
fn datetime(&self) -> Result<&DatetimeChunked>
Unpack to ChunkedArray of dtype datetime
fn duration(&self) -> Result<&DurationChunked>
fn duration(&self) -> Result<&DurationChunked>
Unpack to ChunkedArray of dtype duration
fn list(&self) -> Result<&ListChunked>
fn list(&self) -> Result<&ListChunked>
Unpack to ChunkedArray of dtype list
fn categorical(&self) -> Result<&CategoricalChunked>
fn categorical(&self) -> Result<&CategoricalChunked>
Unpack to ChunkedArray of dtype categorical
fn append_array(&mut self, _other: ArrayRef) -> Result<()>
fn append_array(&mut self, _other: ArrayRef) -> Result<()>
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
fn filter(&self, _filter: &BooleanChunked) -> Result<Series>
fn filter(&self, _filter: &BooleanChunked) -> Result<Series>
Filter by boolean mask. This operation clones data.
fn take_iter(&self, _iter: &mut dyn TakeIterator) -> Result<Series>
fn take_iter(&self, _iter: &mut dyn TakeIterator) -> Result<Series>
Take by index from an iterator. This operation clones the data.
unsafe fn take_iter_unchecked(&self, _iter: &mut dyn TakeIterator) -> Series
unsafe fn take_iter_unchecked(&self, _iter: &mut dyn TakeIterator) -> Series
Take by index from an iterator. This operation clones the data.
Safety
- This doesn’t check any bounds.
- Iterator must be TrustedLen
unsafe fn take_unchecked(&self, _idx: &IdxCa) -> Result<Series>
unsafe fn take_unchecked(&self, _idx: &IdxCa) -> Result<Series>
unsafe fn take_opt_iter_unchecked(
&self,
_iter: &mut dyn TakeIteratorNulls
) -> Series
unsafe fn take_opt_iter_unchecked(
&self,
_iter: &mut dyn TakeIteratorNulls
) -> Series
Take by index from an iterator. This operation clones the data.
Safety
- This doesn’t check any bounds.
- Iterator must be TrustedLen
fn take_opt_iter(&self, _iter: &mut dyn TakeIteratorNulls) -> Result<Series>
fn take_opt_iter(&self, _iter: &mut dyn TakeIteratorNulls) -> Result<Series>
Take by index from an iterator. This operation clones the data.
fn 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.
fn 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)])
fn to_dummies(&self) -> Result<DataFrame>
fn to_dummies(&self) -> Result<DataFrame>
Create dummy variables. See DataFrame
Get a single value by index. Don’t use this operation for loops as a runtime cast is needed for every iteration.
unsafe 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
fn argsort(&self, options: SortOptions) -> IdxCa
fn argsort(&self, options: SortOptions) -> IdxCa
Retrieve the indexes needed for a sort.
fn null_count(&self) -> usize
fn null_count(&self) -> usize
Count the null values.
fn arg_unique(&self) -> Result<IdxCa>
fn arg_unique(&self) -> Result<IdxCa>
Get first indexes of unique values.
fn is_null(&self) -> BooleanChunked
fn is_null(&self) -> BooleanChunked
Get a mask of the null values.
fn is_not_null(&self) -> BooleanChunked
fn is_not_null(&self) -> BooleanChunked
Get a mask of the non-null values.
fn is_unique(&self) -> Result<BooleanChunked>
fn is_unique(&self) -> Result<BooleanChunked>
Get a mask of all the unique values.
fn is_duplicated(&self) -> Result<BooleanChunked>
fn is_duplicated(&self) -> Result<BooleanChunked>
Get a mask of all the duplicated values.
fn as_single_ptr(&mut self) -> Result<usize>
fn as_single_ptr(&mut self) -> Result<usize>
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() -> Result<()> {
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();
fn fill_null(&self, _strategy: FillNullStrategy) -> Result<Series>
fn fill_null(&self, _strategy: FillNullStrategy) -> Result<Series>
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() -> Result<()> {
let s = Series::new("some_missing", &[Some(1), None, Some(2)]);
let filled = s.fill_null(FillNullStrategy::Forward)?;
assert_eq!(Vec::from(filled.i32()?), &[Some(1), Some(1), Some(2)]);
let filled = s.fill_null(FillNullStrategy::Backward)?;
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();
fn _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.
fn max_as_series(&self) -> Series
fn max_as_series(&self) -> Series
Get the max of the Series as a new Series of length 1.
fn min_as_series(&self) -> Series
fn min_as_series(&self) -> Series
Get the min of the Series as a new Series of length 1.
fn median_as_series(&self) -> Series
fn median_as_series(&self) -> Series
Get the median of the Series as a new Series of length 1.
fn var_as_series(&self) -> Series
fn var_as_series(&self) -> Series
Get the variance of the Series as a new Series of length 1.
fn std_as_series(&self) -> Series
fn std_as_series(&self) -> Series
Get the standard deviation of the Series as a new Series of length 1.
fn quantile_as_series(
&self,
_quantile: f64,
_interpol: QuantileInterpolOptions
) -> Result<Series>
fn quantile_as_series(
&self,
_quantile: f64,
_interpol: QuantileInterpolOptions
) -> Result<Series>
Get the quantile of the ChunkedArray as a new Series of length 1.
fn clone_inner(&self) -> Arc<dyn SeriesTrait>
fn clone_inner(&self) -> Arc<dyn SeriesTrait>
Clone inner ChunkedArray and wrap in a new Arc
fn get_object(&self, _index: usize) -> Option<&dyn PolarsObjectSafe>
fn get_object(&self, _index: usize) -> Option<&dyn PolarsObjectSafe>
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
Raise a numeric series to the power of exponent.
fn peak_max(&self) -> BooleanChunked
fn peak_max(&self) -> BooleanChunked
Get a boolean mask of the local maximum peaks.
fn peak_min(&self) -> BooleanChunked
fn peak_min(&self) -> BooleanChunked
Get a boolean mask of the local minimum peaks.
fn is_in(&self, _other: &Series) -> Result<BooleanChunked>
fn is_in(&self, _other: &Series) -> Result<BooleanChunked>
Check if elements of this Series are in the right Series, or List values of the right Series.
fn repeat_by(&self, _by: &IdxCa) -> ListChunked
fn checked_div(&self, _rhs: &Series) -> Result<Series>
fn is_first(&self) -> Result<BooleanChunked>
fn is_first(&self) -> Result<BooleanChunked>
Get a mask of the first unique values.
fn rolling_apply(
&self,
_f: &dyn Fn(&Series) -> Series,
_options: RollingOptions
) -> Result<Series>
fn rolling_apply(
&self,
_f: &dyn Fn(&Series) -> Series,
_options: RollingOptions
) -> Result<Series>
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.
fn str_concat(&self, _delimiter: &str) -> Utf8Chunked
fn str_concat(&self, _delimiter: &str) -> Utf8Chunked
Concat the values into a string array.
Arguments
delimiter
- A string that will act as delimiter between values.
Implementations
sourceimpl<'a> dyn SeriesTrait + 'a
impl<'a> dyn SeriesTrait + 'a
pub fn unpack<N: 'static>(&self) -> Result<&ChunkedArray<N>> where
N: PolarsDataType,
Trait Implementations
sourceimpl<'a, T> AsMut<ChunkedArray<T>> for dyn SeriesTrait + 'a where
T: 'static + PolarsDataType,
impl<'a, T> AsMut<ChunkedArray<T>> for dyn SeriesTrait + 'a where
T: 'static + PolarsDataType,
sourcefn as_mut(&mut self) -> &mut ChunkedArray<T>
fn as_mut(&mut self) -> &mut ChunkedArray<T>
Performs the conversion.
sourceimpl<'a, T> AsRef<ChunkedArray<T>> for dyn SeriesTrait + 'a where
T: 'static + PolarsDataType,
impl<'a, T> AsRef<ChunkedArray<T>> for dyn SeriesTrait + 'a where
T: 'static + PolarsDataType,
sourcefn as_ref(&self) -> &ChunkedArray<T>
fn as_ref(&self) -> &ChunkedArray<T>
Performs the conversion.
sourceimpl<'a> AsRef<dyn SeriesTrait + 'a> for Series
impl<'a> AsRef<dyn SeriesTrait + 'a> for Series
sourcefn as_ref(&self) -> &(dyn SeriesTrait + 'a)
fn as_ref(&self) -> &(dyn SeriesTrait + 'a)
Performs the conversion.