Trait tea_core::prelude::AggValidBasic
source · pub trait AggValidBasic<T: IsNone>: IntoIterator<Item = T> + Sized {
Show 20 methods
// Provided methods
fn count(self) -> usize { ... }
fn count_valid(self) -> usize { ... }
fn vfirst(self) -> Option<T> { ... }
fn vlast(self) -> Option<T>
where Self::IntoIter: DoubleEndedIterator { ... }
fn count_none(self) -> usize { ... }
fn vcount_value(self, value: T) -> usize
where T::Inner: PartialEq { ... }
fn vany(self) -> bool
where T::Inner: BoolType { ... }
fn vall(self) -> bool
where T::Inner: BoolType { ... }
fn vsum(self) -> Option<T::Inner>
where T::Inner: Zero { ... }
fn vmean(self) -> f64
where T::Inner: Number { ... }
fn vmean_var(self, min_periods: usize) -> (f64, f64)
where T::Inner: Number { ... }
fn vvar(self, min_periods: usize) -> f64
where T::Inner: Number { ... }
fn vstd(self, min_periods: usize) -> f64
where T::Inner: Number { ... }
fn vskew(self, min_periods: usize) -> f64
where T::Inner: Number { ... }
fn vmax(self) -> Option<T::Inner>
where T::Inner: Number { ... }
fn vmin(self) -> Option<T::Inner>
where T::Inner: Number { ... }
fn vargmax(self) -> Option<usize>
where T::Inner: PartialOrd { ... }
fn vargmin(self) -> Option<usize>
where T::Inner: PartialOrd { ... }
fn vcov<V2: IntoIterator<Item = T2>, T2: IsNone>(
self,
other: V2,
min_periods: usize,
) -> T::Cast<f64>
where T::Inner: Number,
T2::Inner: Number { ... }
fn vcorr_pearson<O, V2: IntoIterator<Item = T2>, T2: IsNone>(
self,
other: V2,
min_periods: usize,
) -> O
where T::Inner: Number,
T2::Inner: Number,
f64: Cast<O> { ... }
}Provided Methods§
sourcefn count(self) -> usize
👎Deprecated since 0.3.0: Please use count_valid instead
fn count(self) -> usize
count the number of valid elements in the vector.
sourcefn count_valid(self) -> usize
fn count_valid(self) -> usize
Counts the number of valid (non-None) elements in the iterator.
This method iterates through all elements and counts those that are not None.
§Returns
Returns the count of valid elements as a usize.
§Examples
use tea_core::prelude::*;
let vec = vec![Some(1), None, Some(2), None, Some(3)];
assert_eq!(vec.count_valid(), 3);sourcefn vfirst(self) -> Option<T>
fn vfirst(self) -> Option<T>
Finds the first valid (non-None) element in the iterator.
This method iterates through the elements and returns the first one that is not None.
§Returns
Returns an Option<T>:
Some(T)if a valid element is foundNoneif no valid elements are found (i.e., all elements are None or the iterator is empty)
§Examples
use tea_core::prelude::*;
let vec = vec![None, Some(1), None, Some(2), Some(3)];
assert_eq!(vec.vfirst(), Some(Some(1)));
let empty_vec: Vec<Option<i32>> = vec![];
assert_eq!(empty_vec.vfirst(), None);sourcefn vlast(self) -> Option<T>where
Self::IntoIter: DoubleEndedIterator,
fn vlast(self) -> Option<T>where
Self::IntoIter: DoubleEndedIterator,
Finds the last valid (non-None) element in the iterator.
This method iterates through the elements in reverse order and returns the first non-None element encountered.
§Returns
Returns an Option<T>:
Some(T)if a valid element is foundNoneif no valid elements are found (i.e., all elements are None or the iterator is empty)
§Examples
use tea_core::prelude::*;
let vec = vec![Some(1), None, Some(2), None, Some(3)];
assert_eq!(vec.vlast(), Some(Some(3)));
let empty_vec: Vec<Option<i32>> = vec![];
assert_eq!(empty_vec.vlast(), None);§Note
This method requires the iterator to be double-ended.
sourcefn count_none(self) -> usize
fn count_none(self) -> usize
Counts the number of None values in the iterator.
This method iterates through all elements and counts those that are None.
§Returns
Returns the count of None values as a usize.
§Examples
use tea_core::prelude::*;
let vec = vec![Some(1), None, Some(2), None, Some(3)];
assert_eq!(vec.count_none(), 2);sourcefn vcount_value(self, value: T) -> usize
fn vcount_value(self, value: T) -> usize
Counts the number of occurrences of a specific value in the iterator.
This method iterates through all elements and counts those that match the given value.
It handles both Some and None values.
§Arguments
value- The value to count occurrences of. It can be eitherSome(T::Inner)orNone.
§Returns
Returns the count of occurrences as a usize.
§Examples
use tea_core::prelude::*;
let vec = vec![Some(1), None, Some(2), Some(1), None, Some(3)];
assert_eq!(vec.titer().vcount_value(Some(1)), 2);
assert_eq!(vec.titer().vcount_value(None), 2);
assert_eq!(vec.vcount_value(Some(4)), 0);sourcefn vany(self) -> bool
fn vany(self) -> bool
Checks if any valid (non-None) element in the iterator satisfies the given condition.
This method iterates through all elements and returns true if any element is not None and satisfies the condition.
§Returns
Returns a bool:
trueif any valid element satisfies the conditionfalseif no valid elements satisfy the condition or the iterator is empty
sourcefn vall(self) -> bool
fn vall(self) -> bool
Checks if all valid (non-None) elements in the iterator satisfy the given condition.
This method iterates through all elements and returns true if all elements are not None and satisfy the condition.
§Returns
Returns a bool:
trueif all valid elements satisfy the conditionfalseif any valid element does not satisfy the condition or the iterator is empty
§Examples
use tea_core::prelude::*;
let vec = vec![Some(true), Some(true), Some(false)];
assert_eq!(vec.vall(), false);
let vec = vec![Some(true), Some(true), Some(true)];
assert_eq!(vec.vall(), true);
let empty_vec: Vec<Option<bool>> = vec![];
assert_eq!(empty_vec.vall(), true); // All elements are None, so it satisfies the conditionsourcefn vsum(self) -> Option<T::Inner>
fn vsum(self) -> Option<T::Inner>
Returns the sum of all valid elements in the vector.
This method iterates through all elements, summing up the valid (non-None) values.
§Returns
Returns an Option<T::Inner>:
Some(sum)if there is at least one valid elementNoneif there are no valid elements or the vector is empty
§Type Parameters
T::Inner: Must implement theZerotrait to provide a zero value for initialization
§Examples
use tea_core::prelude::*;
let vec = vec![Some(1), Some(2), None, Some(3)];
assert_eq!(vec.vsum(), Some(6));
let empty_vec: Vec<Option<i32>> = vec![];
assert_eq!(empty_vec.vsum(), None);
let all_none_vec: Vec<Option<f64>> = vec![None, None, None];
assert_eq!(all_none_vec.vsum(), None);sourcefn vmean(self) -> f64
fn vmean(self) -> f64
Calculates the mean (average) of all valid elements in the vector.
This method iterates through all elements, summing up the valid (non-None) values and counting the number of valid elements. It then calculates the mean by dividing the sum by the count.
§Returns
Returns an f64:
- The calculated mean if there is at least one valid element
f64::NANif there are no valid elements or the vector is empty
§Type Parameters
T::Inner: Must implement theNumbertrait to support arithmetic operations
§Examples
use tea_core::prelude::*;
let vec = vec![Some(1), Some(2), None, Some(3)];
assert_eq!(vec.vmean(), 2.0);
let empty_vec: Vec<Option<i32>> = vec![];
assert!(empty_vec.vmean().is_nan());
let all_none_vec: Vec<Option<f64>> = vec![None, None, None];
assert!(all_none_vec.vmean().is_nan());sourcefn vmean_var(self, min_periods: usize) -> (f64, f64)
fn vmean_var(self, min_periods: usize) -> (f64, f64)
Calculates the mean and variance of all valid elements in the vector.
This method iterates through all elements, computing the sum and sum of squares of valid (non-None) values. It then calculates the mean and variance using these values.
§Arguments
min_periods- The minimum number of valid observations required to calculate the result.
§Returns
Returns a tuple of two f64 values:
- The first element is the calculated mean
- The second element is the calculated variance
- Both elements are
f64::NANif there are fewer valid elements thanmin_periods
§Type Parameters
T::Inner: Must implement theNumbertrait to support arithmetic operations
§Examples
use tea_core::prelude::*;
let vec = vec![Some(1), Some(2), None, Some(3)];
let (mean, var) = vec.vmean_var(1);
assert_eq!(mean, 2.0);
assert!((var - 1.0).abs() < EPS);
let empty_vec: Vec<Option<i32>> = vec![];
let (mean, var) = empty_vec.vmean_var(1);
assert!(mean.is_nan() && var.is_nan());sourcefn vvar(self, min_periods: usize) -> f64
fn vvar(self, min_periods: usize) -> f64
Calculates the variance of the data.
This method computes the variance of the non-null values in the collection.
§Arguments
min_periods- The minimum number of non-null values required to calculate the variance. If the number of non-null values is less thanmin_periods, the method returnsf64::NAN.
§Returns
Returns an f64 representing the variance of the data. If there are fewer valid elements
than min_periods, returns f64::NAN.
§Examples
use tea_core::prelude::*;
let vec = vec![Some(1), Some(2), None, Some(3)];
let var = vec.vvar(1);
assert!((var - 1.0).abs() < EPS);
let empty_vec: Vec<Option<i32>> = vec![];
let var = empty_vec.vvar(1);
assert!(var.is_nan());sourcefn vstd(self, min_periods: usize) -> f64
fn vstd(self, min_periods: usize) -> f64
Calculates the standard deviation of the data.
This method computes the standard deviation of the non-null values in the collection.
§Arguments
min_periods- The minimum number of non-null values required to calculate the standard deviation. If the number of non-null values is less thanmin_periods, the method returnsf64::NAN.
§Returns
Returns an f64 representing the standard deviation of the data. If there are fewer valid elements
than min_periods, returns f64::NAN.
§Examples
use tea_core::prelude::*;
let vec = vec![Some(1), Some(2), None, Some(3)];
let std = vec.vstd(1);
assert!((std - 1.0).abs() < EPS);
let empty_vec: Vec<Option<i32>> = vec![];
let std = empty_vec.vstd(1);
assert!(std.is_nan());sourcefn vskew(self, min_periods: usize) -> f64
fn vskew(self, min_periods: usize) -> f64
Calculates the skewness of the data.
Skewness is a measure of the asymmetry of the probability distribution of a real-valued random variable about its mean.
§Arguments
min_periods- The minimum number of non-null values required to calculate the skewness. If the number of non-null values is less thanmin_periods, the method returnsf64::NAN.
§Returns
Returns an f64 representing the skewness of the data. If there are fewer valid elements
than min_periods, or if the number of elements is less than 3, returns f64::NAN.
§Examples
use tea_core::prelude::*;
let vec = vec![Some(1), Some(2), Some(3), Some(4), Some(5)];
let skew = vec.vskew(1);
assert!((skew - 0.0).abs() < EPS);
let empty_vec: Vec<Option<i32>> = vec![];
let skew = empty_vec.vskew(1);
assert!(skew.is_nan());sourcefn vmax(self) -> Option<T::Inner>
fn vmax(self) -> Option<T::Inner>
Returns the maximum value in the vector.
This method iterates through the vector and returns the maximum value.
If the vector is empty or contains only None values, it returns None.
§Examples
use tea_core::prelude::*;
let vec = vec![Some(1), Some(5), Some(3), Some(2), Some(4)];
assert_eq!(vec.vmax(), Some(5));
let empty_vec: Vec<Option<i32>> = vec![];
assert_eq!(empty_vec.vmax(), None);
let none_vec: Vec<Option<i32>> = vec![None, None, None];
assert_eq!(none_vec.vmax(), None);sourcefn vmin(self) -> Option<T::Inner>
fn vmin(self) -> Option<T::Inner>
Returns the minimum value in the vector.
This method iterates through the vector and returns the minimum value.
If the vector is empty or contains only None values, it returns None.
§Examples
use tea_core::prelude::*;
let vec = vec![Some(1), Some(5), Some(3), Some(2), Some(4)];
assert_eq!(vec.vmin(), Some(1));
let empty_vec: Vec<Option<i32>> = vec![];
assert_eq!(empty_vec.vmin(), None);
let none_vec: Vec<Option<i32>> = vec![None, None, None];
assert_eq!(none_vec.vmin(), None);sourcefn vargmax(self) -> Option<usize>where
T::Inner: PartialOrd,
fn vargmax(self) -> Option<usize>where
T::Inner: PartialOrd,
Returns the index of the maximum value in the vector.
This method iterates through the vector and returns the index of the maximum value.
If the vector is empty or contains only None values, it returns None.
§Examples
use tea_core::prelude::*;
let vec = vec![Some(1), Some(5), Some(3), Some(2), Some(4)];
assert_eq!(vec.vargmax(), Some(1)); // Index of 5
let empty_vec: Vec<Option<i32>> = vec![];
assert_eq!(empty_vec.vargmax(), None);
let none_vec: Vec<Option<i32>> = vec![None, None, None];
assert_eq!(none_vec.vargmax(), None);sourcefn vargmin(self) -> Option<usize>where
T::Inner: PartialOrd,
fn vargmin(self) -> Option<usize>where
T::Inner: PartialOrd,
Returns the index of the minimum value in the vector.
This method iterates through the vector and returns the index of the minimum value.
If the vector is empty or contains only None values, it returns None.
§Examples
use tea_core::prelude::*;
let vec = vec![Some(3), Some(1), Some(4), Some(2), Some(5)];
assert_eq!(vec.vargmin(), Some(1)); // Index of 1
let empty_vec: Vec<Option<i32>> = vec![];
assert_eq!(empty_vec.vargmin(), None);
let none_vec: Vec<Option<i32>> = vec![None, None, None];
assert_eq!(none_vec.vargmin(), None);sourcefn vcov<V2: IntoIterator<Item = T2>, T2: IsNone>(
self,
other: V2,
min_periods: usize,
) -> T::Cast<f64>
fn vcov<V2: IntoIterator<Item = T2>, T2: IsNone>( self, other: V2, min_periods: usize, ) -> T::Cast<f64>
Calculates the covariance between two vectors.
This method computes the covariance between the elements of self and other.
§Arguments
other- An iterator over the second vector of values.min_periods- The minimum number of pairs of non-None values required to have a valid result.
§Returns
Returns the covariance as T::Cast<f64>. If there are fewer valid pairs than min_periods,
or if the computation results in NaN, returns None.
§Type Parameters
V2- The type of the iterator for the second vector.T2- The type of elements in the second vector, which must implementIsNone.
sourcefn vcorr_pearson<O, V2: IntoIterator<Item = T2>, T2: IsNone>(
self,
other: V2,
min_periods: usize,
) -> O
fn vcorr_pearson<O, V2: IntoIterator<Item = T2>, T2: IsNone>( self, other: V2, min_periods: usize, ) -> O
Calculates the Pearson correlation coefficient between two vectors.
This method computes the Pearson correlation coefficient between the elements of self and other.
§Arguments
other- An iterator over the second vector of values.min_periods- The minimum number of pairs of non-None values required to have a valid result.
§Returns
Returns the Pearson correlation coefficient as type O. If there are fewer valid pairs than min_periods,
or if the computation results in NaN (e.g., due to zero variance), returns NaN.
§Type Parameters
O- The output type for the correlation coefficient.V2- The type of the iterator for the second vector.T2- The type of elements in the second vector, which must implementIsNone.