pub struct DataColumn {
pub name: Option<String>,
/* private fields */
}
Expand description
A data column consisting of Strings.
Fields§
§name: Option<String>
The name associated with the DataColumn.
Implementations§
Source§impl DataColumn
impl DataColumn
Sourcepub fn empty() -> DataColumn
pub fn empty() -> DataColumn
Constructs an empty data column.
Sourcepub fn categories(&self) -> Option<HashMap<String, usize>>
pub fn categories(&self) -> Option<HashMap<String, usize>>
Gets an immutable reference to the categories Option.
Sourcepub fn update_categories(&mut self)
pub fn update_categories(&mut self)
Update the categories set using the current data.
§Examples
use rusty_data::datatable::DataColumn;
let mut dc = DataColumn::empty();
dc.push("Class1".to_string());
dc.push("Class2".to_string());
dc.push("Class2".to_string());
dc.update_categories();
let categories = dc.categories().unwrap();
// Note that `contains` requires a reference so we pass an &str.
assert!(categories.contains_key("Class2"));
assert_eq!(categories.len(), 2);
Sourcepub fn numeric_category_data<T: Zero + One>(
&self,
) -> Result<Vec<Vec<T>>, DataError>
pub fn numeric_category_data<T: Zero + One>( &self, ) -> Result<Vec<Vec<T>>, DataError>
Produce a numerical vector representation of the category data.
§Examples
use rusty_data::datatable::DataColumn;
let mut dc = DataColumn::empty();
dc.push("Class1".to_string());
dc.push("Class2".to_string());
dc.push("Class2".to_string());
dc.update_categories();
let data = dc.numeric_category_data::<f64>().unwrap();
println!("The data is: {:?}", data);
Sourcepub fn get_as<T: FromStr>(&self, idx: usize) -> Result<T, DataError>
pub fn get_as<T: FromStr>(&self, idx: usize) -> Result<T, DataError>
Try to get the element at the index as the requested type.
§Failures
- DataCastError : The element at the given index could not be parsed to this type.
Sourcepub fn shrink_to_fit(&mut self)
pub fn shrink_to_fit(&mut self)
Shrink the column to fit the data.
Sourcepub fn into_vec<T: FromStr>(self) -> Result<Vec<T>, DataError>
pub fn into_vec<T: FromStr>(self) -> Result<Vec<T>, DataError>
Consumes self and returns a Vec of the requested type.
§Failures
- DataCastError : Returned when the data cannot be parsed to the requested type.
Sourcepub fn cast<T: FromStr>(&self) -> Option<Vec<T>>
pub fn cast<T: FromStr>(&self) -> Option<Vec<T>>
Cast the data to the requested type.
Returns a Vec of the requested type wrapped in an option.
Sourcepub fn into_iter_cast<U>(
self,
) -> Map<IntoIter<String>, fn(String) -> Result<U, <U as FromStr>::Err>>where
U: FromStr,
pub fn into_iter_cast<U>(
self,
) -> Map<IntoIter<String>, fn(String) -> Result<U, <U as FromStr>::Err>>where
U: FromStr,
Consumes self and returns an iterator which parses the data to the specified type returning results.
The iterator will return a result on next()
detailing
the outcome of the parse.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for DataColumn
impl RefUnwindSafe for DataColumn
impl Send for DataColumn
impl Sync for DataColumn
impl Unpin for DataColumn
impl UnwindSafe for DataColumn
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more