pub trait AggValidBasic<T>: Sized + IntoIterator<Item = T>where
T: IsNone,{
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 as IsNone>::Inner: PartialEq { ... }
fn vany(self) -> bool
where <T as IsNone>::Inner: BoolType { ... }
fn vall(self) -> bool
where <T as IsNone>::Inner: BoolType { ... }
fn vsum(self) -> Option<<T as IsNone>::Inner>
where <T as IsNone>::Inner: Zero { ... }
fn vmean(self) -> f64
where <T as IsNone>::Inner: Number { ... }
fn vmean_var(self, min_periods: usize) -> (f64, f64)
where <T as IsNone>::Inner: Number { ... }
fn vvar(self, min_periods: usize) -> f64
where <T as IsNone>::Inner: Number { ... }
fn vstd(self, min_periods: usize) -> f64
where <T as IsNone>::Inner: Number { ... }
fn vskew(self, min_periods: usize) -> f64
where <T as IsNone>::Inner: Number { ... }
fn vmax(self) -> Option<<T as IsNone>::Inner>
where <T as IsNone>::Inner: Number { ... }
fn vmin(self) -> Option<<T as IsNone>::Inner>
where <T as IsNone>::Inner: Number { ... }
fn vargmax(self) -> Option<usize>
where <T as IsNone>::Inner: PartialOrd { ... }
fn vargmin(self) -> Option<usize>
where <T as IsNone>::Inner: PartialOrd { ... }
fn vcov<V2, T2>(
self,
other: V2,
min_periods: usize,
) -> <T as IsNone>::Cast<f64>
where V2: IntoIterator<Item = T2>,
T2: IsNone,
<T as IsNone>::Inner: Number,
<T2 as IsNone>::Inner: Number { ... }
fn vcorr_pearson<O, V2, T2>(self, other: V2, min_periods: usize) -> O
where V2: IntoIterator<Item = T2>,
T2: IsNone,
<T as IsNone>::Inner: Number,
<T2 as IsNone>::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 as IsNone>::Inner>
fn vsum(self) -> Option<<T as IsNone>::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 as IsNone>::Inner>
fn vmax(self) -> Option<<T as IsNone>::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 as IsNone>::Inner>
fn vmin(self) -> Option<<T as IsNone>::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>
fn vargmax(self) -> Option<usize>
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>
fn vargmin(self) -> Option<usize>
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, T2>(self, other: V2, min_periods: usize) -> <T as IsNone>::Cast<f64>
fn vcov<V2, T2>(self, other: V2, min_periods: usize) -> <T as IsNone>::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, T2>(self, other: V2, min_periods: usize) -> O
fn vcorr_pearson<O, V2, T2>(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.
Dyn Compatibilityยง
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.