Series

Struct Series 

Source
pub struct Series<T>
where T: BlackJackData,
{ pub name: Option<String>, pub values: Vec<T>, /* private fields */ }
Expand description

Series struct for containing underlying Array and other meta data.

Fields§

§name: Option<String>

Name of the series, if added to a dataframe without a name, it will be assigned a default name equalling the count of columns in the dataframe.

§values: Vec<T>

The underlying values of the Series

Implementations§

Source§

impl<T> Series<T>
where T: BlackJackData,

Constructor methods for Series<T>

Source

pub fn arange(start: T, stop: T) -> Self

Create a new Series struct from an integer range with one step increments.

§Example
use blackjack::prelude::*;

let series: Series<i32> = Series::arange(0, 10);
Source

pub fn drop_positions<I>(&mut self, positions: I)
where I: IntoIterator<Item = usize>,

Drop positions of the Series

Source

pub fn iloc<'b, I>(&self, idx_vals: I) -> Vec<&T>
where I: IntoIterator<Item = &'b usize>,

Fetch values from the series by matching index positions, not by index value.

No data copies are made, and currently this is not done in parallel. As by currently single threaded exceeds parallel execution up to ~10m elements. As the majority of use cases have less than this amount, we’ve opted for single threading. If you need concurrent execution, please file an issue at our github. :-)

§Example
use blackjack::prelude::*;

let mut series = Series::arange(0, 10000);  // Index values end up being 0-10000 by default here

let vals = series.iloc(&vec![250, 500, 1000, 2000, 4000, 5000]);  // ~300ns, ~28x faster than Pandas
assert_eq!(vals, vec![&250, &500, &1000, &2000, &4000, &5000]);
Source

pub fn rolling(&self, window: usize) -> Rolling<'_, T>
where T: Send + Sync,

Calculate a predefined rolling aggregation

See Rolling for additional functionality.

§Example
use blackjack::prelude::*;
use float_cmp::ApproxEq;

let series = Series::from_vec(vec![0, 1, 2, 3, 4, 5]);

let rolled: Series<f64> = series.rolling(4).mean().unwrap();
assert_eq!(rolled.len(), 6);

// vals in indexes 0 thru 2 should be NaN as they are inside the window
assert_eq!(rolled[0..2].iter().all(|v| v.is_nan()), true);

assert_eq!(rolled[3], 1.5);
assert_eq!(rolled[4], 2.5);
assert_eq!(rolled[5], 3.5);
Source

pub fn isna<'a>(&'a self) -> impl Iterator<Item = bool> + 'a
where T: Float,

Return an iterable of booleans determining if any element is NaN

§Example
use blackjack::prelude::*;

let mut series = Series::from_vec(vec![0, 1, 2])
    .astype::<f32>()
    .unwrap();

// No NaNs currently
assert_eq!(series.isna().collect::<Vec<bool>>(), vec![false, false, false]);

// Insert a NaN at index zero
series[0] = num::Float::nan();
assert_eq!(series.isna().collect::<Vec<bool>>(), vec![true, false, false]);
Source

pub fn all<F>(&self, condition: F) -> bool
where for<'r> F: Fn(&'r T) -> bool,

Determine if all elements in the Series meet a given condition

This will stop iteration after encountering the first element which breaks the condition.

§Example
use blackjack::prelude::*;

let series = Series::from_vec(vec![1, 2, 3, 4]);

assert_eq!(series.all(|x| *x > 0), true);
assert_eq!(series.all(|x| *x > 2), false);
Source

pub fn all_equal(&self) -> bool
where T: PartialEq,

Check if all elements with the Series are equal

§Example
use blackjack::prelude::*;

let series = Series::from_vec(vec![1, 1, 1, 1, 1]);
assert!(series.all_equal());
Source

pub fn any<F>(&self, condition: F) -> bool
where for<'r> F: FnMut(&'r &T) -> bool,

Determine if any element in the Series meets a given condition

This will stop iteration after encountering the first element which meets conditions supplied.

Source

pub fn cartesian_product<O>(&self, other: &Series<O>) -> (Series<T>, Series<O>)
where O: BlackJackData,

Create a cartesian product of this series and another, returns a pair of Series representing the cartesian product

§Example
use blackjack::prelude::*;

let series1 = Series::from_vec(vec![0, 1]);
let series2 = Series::from_vec(vec![1, 2]);

let (cart_prod1, cart_prod2) = series1.cartesian_product(&series2);

assert_eq!(cart_prod1.values, vec![0, 0, 1, 1]);
assert_eq!(cart_prod2.values, vec![1, 2, 1, 2]);
Source

pub fn positions<'a, F>( &'a self, condition: F, ) -> impl Iterator<Item = usize> + 'a
where F: 'a + Fn(&T) -> bool,

Return the positions of where a given condition evaluates to true

This is somewhat akin to the pandas where method.

§Example
use blackjack::prelude::*;

let series = Series::from_vec(vec![1, 2, 1, 2]);

let indexes_of_ones = series.positions(|x| *x == 1).collect::<Vec<usize>>();
assert_eq!(indexes_of_ones, vec![0, 2]);
Source

pub fn map_par<B, F>(self, func: F) -> Series<B>
where B: BlackJackData, F: Fn(T) -> B + Send + Sync,

Map a function over a series in parallel Function takes some type T and returns some type B which has BlackJackData implemented.

§Example
use blackjack::prelude::*;

let series = Series::from_vec(vec![1, 1, 1, 1]);

let new_series = series.map_par(|x| x * 2);
assert_eq!(new_series.sum(), 8);
Source

pub fn map<B, F>(self, func: F) -> Series<B>
where B: BlackJackData, F: Fn(T) -> B,

Map a function over a series in a single thread Function takes some type T and returns some type B which has BlackJackData implemented.

Source

pub fn astype<A>(&self) -> Result<Series<A>, &'static str>

Convert the series into another DType (creates a new series)

§Example
use blackjack::prelude::*;

let series: Series<i32> = Series::arange(0, 10);
assert_eq!(series[0].dtype(), DType::I32);
let new_series = series.astype::<f64>().unwrap();
assert_eq!(new_series[0].dtype(), DType::F64);
Source

pub fn into_type<A>(self) -> Result<Series<A>, &'static str>

Convert this series into another DType (consumes current series)

§Example
use blackjack::prelude::*;

let series: Series<i32> = Series::arange(0, 10);
assert_eq!(series[0].dtype(), DType::I32);
let new_series = series.into_type::<f64>().unwrap();
assert_eq!(new_series[0].dtype(), DType::F64);
Source

pub fn unique(&self) -> Series<T>
where T: PartialOrd + Copy,

Get a series of the unique elements held in this series

§Example
use blackjack::prelude::*;

let series: Series<i32> = Series::from_vec(vec![1, 2, 1, 0, 1, 0, 1, 1]);
let unique: Series<i32> = series.unique();
assert_eq!(unique, Series::from_vec(vec![0, 1, 2]));
Source

pub fn from_vec(vec: Vec<T>) -> Self

Create a new Series struct from a vector, where T is supported by BlackJackData.

§Example
use blackjack::prelude::*;

let series: Series<i32> = Series::from_vec(vec![1, 2, 3]);
Source

pub fn into_vec(self) -> Vec<T>

Convert the series to a Vec

§Example
use blackjack::prelude::*;

let series = Series::from_vec(vec![1_f64, 2_f64, 3_f64]);

assert_eq!(
    series.clone().into_vec(),
    vec![1_f64, 2_f64, 3_f64]
);
Source

pub fn set_name(&mut self, name: &str)

Set the name of a series

Source

pub fn name(&self) -> Option<String>

Get the name of the series; Series may not be assigned a string, so an Option is returned.

§Example
use blackjack::prelude::*;

let mut series = Series::from_vec(vec![1, 2, 3]);
series.set_name("my-series");

assert_eq!(series.name(), Some("my-series".to_string()));
Source

pub fn mode(&self) -> Result<Self, BlackJackError>

Finds the returns a Series containing the mode(s) of the current Series

Source

pub fn var(&self, ddof: f64) -> Result<f64, BlackJackError>
where T: ToPrimitive + Num,

Calculate the variance of the series, using either population or sample variance

Population: ddof == 0_f64 Sample: ddof == 1_f64

Source

pub fn std(&self, ddof: f64) -> Result<f64, BlackJackError>

Calculate the standard deviation of the series

§Example
use blackjack::prelude::*;
use float_cmp::ApproxEq;

let series = Series::arange(0, 10).astype::<f32>().unwrap();

let std = series.std(1_f64).unwrap(); // using population ddof (sample variance == 0_f64)
assert_eq!(std, 3.0276503540974917);
Source

pub fn sum(&self) -> T
where T: Num + Copy + Sum,

Sum a given series, yielding the same type as the elements stored in the series.

Source

pub fn mean(&self) -> Result<f64, BlackJackError>
where T: ToPrimitive + Copy + Num + Sum,

Average / Mean of a given series - Requires specifying desired float return annotation

§Example:
use blackjack::prelude::*;

let series = Series::arange(0, 5);
let mean = series.mean();

match mean {
    Ok(result) => {
        println!("Result is: {}", &result);
        assert_eq!(result, 2.0);
    },
    Err(err) => {
        panic!("Was unable to compute mean, error: {}", err);
    }
}
Source

pub fn quantile(&self, quantile: f64) -> Result<f64, BlackJackError>

Calculate the quantile of the series

§Example:
use blackjack::prelude::*;

let series = Series::arange(0, 100).astype::<f32>().unwrap();
let qtl = series.quantile(0.5).unwrap(); // `49.5_f32`

assert!(qtl < 49.51);
assert!(qtl > 49.49);
Source

pub fn median(&self) -> Result<f64, BlackJackError>

Calculate the median of a series

Source

pub fn min(&self) -> Result<T, BlackJackError>

Find the minimum of the series. If several elements are equally minimum, the first element is returned. If it’s empty, an Error will be returned.

§Example
use blackjack::prelude::*;

let series: Series<i32> = Series::arange(10, 100);

assert_eq!(series.min().unwrap(), 10);
Source

pub fn max(&self) -> Result<T, BlackJackError>

Exibits the same behavior and usage of Series::min, only yielding the Result of a maximum.

Source

pub fn len(&self) -> usize

Determine the length of the Series

Source

pub fn is_empty(&self) -> bool

Determine if series is empty.

Source

pub fn dtype(&self) -> Option<DType>

Get the dtype, returns None if series dtype is unknown. in such a case, calling .astype() to coerce all types to a single type is needed.

Source

pub fn append<V: Into<T>>(&mut self, val: V)

Append a BlackJackData element to the Series

§Example
use blackjack::prelude::*;

let mut series = Series::from_vec(vec![0, 1, 2]);
assert_eq!(series.len(), 3);

series.append(3);
assert_eq!(series.len(), 4);
Source

pub fn into_raw(self) -> *mut Self

As boxed pointer, recoverable by Box::from_raw(ptr) or Series::from_raw(*mut Self)

Source

pub fn from_raw(ptr: *mut Self) -> Self

Create from raw pointer

Source

pub fn groupby(&self, keys: &Series<T>) -> SeriesGroupBy<T>
where T: ToPrimitive,

Group by method for grouping elements in a Series by key.

§Example
use blackjack::prelude::*;

let series = Series::from_vec(vec![1, 2, 3, 1, 2, 3]);
let keys   = Series::from_vec(vec![4, 5, 6, 4, 5, 6]);

let grouped: Series<i32> = series.groupby(&keys).sum();
assert_eq!(grouped.len(), 3);

let mut vals = grouped.into_vec();
vals.sort();
assert_eq!(vals, vec![2, 4, 6]);
Source

pub fn find<F: Fn(&T) -> bool>(&self, condition: F) -> Vec<usize>

Find the positions where a condition is true

§Example

let series = Series::from(0..10);
let positions = series.find(|v| v % 2 == 0);

assert_eq!(positions, vec![0, 2, 4, 6, 8]);

Trait Implementations§

Source§

impl<T> Add<T> for Series<T>

Support series + scalar

Source§

type Output = Series<T>

The resulting type after applying the + operator.
Source§

fn add(self, scalar_val: T) -> Series<T>

Performs the + operation. Read more
Source§

impl<T> Add for Series<T>
where T: Add<Output = T> + BlackJackData,

Support series + series

Source§

type Output = Result<Series<T>, BlackJackError>

The resulting type after applying the + operator.
Source§

fn add(self, other: Series<T>) -> Self::Output

Performs the + operation. Read more
Source§

impl<T> AddAssign<T> for Series<T>

Support series += scalar

Source§

fn add_assign(&mut self, scalar_val: T)

Performs the += operation. Read more
Source§

impl<T> AddAssign for Series<T>

Source§

fn add_assign(&mut self, other: Series<T>)

Performs the += operation. Read more
Source§

impl<T> Clone for Series<T>
where T: BlackJackData + Clone,

Source§

fn clone(&self) -> Series<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T> Debug for Series<T>
where T: BlackJackData + Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<I> Default for Series<I>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de, T> Deserialize<'de> for Series<T>
where T: BlackJackData + Deserialize<'de>,

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<T> Display for Series<T>
where T: BlackJackData, String: From<T>,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T> Div<T> for Series<T>

Support series - scalar

Source§

type Output = Series<T>

The resulting type after applying the / operator.
Source§

fn div(self, scalar_val: T) -> Series<T>

Performs the / operation. Read more
Source§

impl<T> Div for Series<T>
where T: Div<Output = T> + BlackJackData,

Support series + series

Source§

type Output = Result<Series<T>, BlackJackError>

The resulting type after applying the / operator.
Source§

fn div(self, other: Series<T>) -> Self::Output

Performs the / operation. Read more
Source§

impl<T> DivAssign<T> for Series<T>

Support series += scalar

Source§

fn div_assign(&mut self, scalar_val: T)

Performs the /= operation. Read more
Source§

impl<T> DivAssign for Series<T>

Source§

fn div_assign(&mut self, other: Series<T>)

Performs the /= operation. Read more
Source§

impl<T: BlackJackData> From<&Series<T>> for SeriesMeta

Source§

fn from(series: &Series<T>) -> SeriesMeta

Converts to this type from the input type.
Source§

impl<T> From<Range<T>> for Series<T>

Source§

fn from(range: Range<T>) -> Series<T>

Converts to this type from the input type.
Source§

impl<T> Index<Range<usize>> for Series<T>
where T: BlackJackData,

Source§

type Output = [T]

The returned type after indexing.
Source§

fn index(&self, idx: Range<usize>) -> &[T]

Performs the indexing (container[index]) operation. Read more
Source§

impl<T> Index<usize> for Series<T>
where T: BlackJackData,

Source§

type Output = T

The returned type after indexing.
Source§

fn index(&self, idx: usize) -> &T

Performs the indexing (container[index]) operation. Read more
Source§

impl<T: BlackJackData> IndexMut<usize> for Series<T>

Source§

fn index_mut(&mut self, idx: usize) -> &mut T

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl IntoIterator for Series<String>

Source§

type Item = String

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<String>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl IntoIterator for Series<f32>

Source§

type Item = f32

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<f32>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl IntoIterator for Series<f64>

Source§

type Item = f64

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<f64>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl IntoIterator for Series<i32>

Source§

type Item = i32

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<i32>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl IntoIterator for Series<i64>

Source§

type Item = i64

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<i64>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<T> Mul<T> for Series<T>

Support series * scalar

Source§

type Output = Series<T>

The resulting type after applying the * operator.
Source§

fn mul(self, scalar_val: T) -> Series<T>

Performs the * operation. Read more
Source§

impl<T> Mul for Series<T>
where T: Mul<Output = T> + BlackJackData,

Support series + series

Source§

type Output = Result<Series<T>, BlackJackError>

The resulting type after applying the * operator.
Source§

fn mul(self, other: Series<T>) -> Self::Output

Performs the * operation. Read more
Source§

impl<T> MulAssign<T> for Series<T>

Source§

fn mul_assign(&mut self, scalar_val: T)

Performs the *= operation. Read more
Source§

impl<T> MulAssign for Series<T>

Source§

fn mul_assign(&mut self, other: Series<T>)

Performs the *= operation. Read more
Source§

impl<T> PartialEq for Series<T>

Source§

fn eq(&self, other: &Series<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T> PartialOrd for Series<T>

Source§

fn partial_cmp(&self, other: &Series<T>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<T> Serialize for Series<T>

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<T> Sub<T> for Series<T>

Support series - scalar

Source§

type Output = Series<T>

The resulting type after applying the - operator.
Source§

fn sub(self, scalar_val: T) -> Series<T>

Performs the - operation. Read more
Source§

impl<T> Sub for Series<T>
where T: Sub<Output = T> + BlackJackData,

Support series + series

Source§

type Output = Result<Series<T>, BlackJackError>

The resulting type after applying the - operator.
Source§

fn sub(self, other: Series<T>) -> Self::Output

Performs the - operation. Read more
Source§

impl<T> SubAssign<T> for Series<T>

Support series -= scalar

Source§

fn sub_assign(&mut self, scalar_val: T)

Performs the -= operation. Read more
Source§

impl<T> SubAssign for Series<T>

Source§

fn sub_assign(&mut self, other: Series<T>)

Performs the -= operation. Read more
Source§

impl<T> StructuralPartialEq for Series<T>
where T: BlackJackData,

Auto Trait Implementations§

§

impl<T> Freeze for Series<T>

§

impl<T> RefUnwindSafe for Series<T>
where T: RefUnwindSafe,

§

impl<T> Send for Series<T>

§

impl<T> Sync for Series<T>
where T: Sync,

§

impl<T> Unpin for Series<T>
where T: Unpin,

§

impl<T> UnwindSafe for Series<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,