Skip to main content

Column

Struct Column 

Source
pub struct Column { /* private fields */ }
Expand description

One named column of a Table.

A column pairs the values of one source column with the name that the source gives it. The name is fixed when the column is built.

§Examples

use dataset_ml::table::{Column, ColumnData};
use ndarray::array;

let column = Column::new("petal_width", ColumnData::Numeric(array![0.2, 1.4]));

assert_eq!(column.name(), "petal_width");
assert_eq!(column.len(), 2);
assert_eq!(column.as_numeric().unwrap()[0], 0.2);

// An `as_*` method returns `None` for every other variant.
assert!(column.as_string().is_none());

Implementations§

Source§

impl Column

Source

pub fn new(name: &'static str, data: ColumnData) -> Self

Build a column from its name and its values.

§Parameters
  • name - The name the source gives the column.
  • data - The values in the column.
§Returns
  • Self - the new column.
Source

pub fn name(&self) -> &'static str

The column’s name.

§Returns
  • &'static str - the name, as the source spells it.
Source

pub fn data(&self) -> &ColumnData

The column’s values.

§Returns
  • &ColumnData - a shared reference to the values.
Source

pub fn data_mut(&mut self) -> &mut ColumnData

The column’s values, for in-place editing.

§Returns
  • &mut ColumnData - a mutable reference to the values.
§Notes

Change a value, but do not change the number of samples. A Table that holds this column relies on every column having the same length.

Source

pub fn len(&self) -> usize

The number of samples the column holds.

§Returns
  • usize - the sample count.
Source

pub fn is_empty(&self) -> bool

Whether the column holds no sample.

§Returns
  • bool - true if the column holds no sample, and false if it holds at least one.
Source

pub fn as_numeric(&self) -> Option<&Array1<f64>>

The values, if the column is ColumnData::Numeric.

§Returns
  • Some(&Array1<f64>) - the values, one per sample.
  • None - if the column holds another variant.
Source

pub fn as_integer(&self) -> Option<&Array1<i64>>

The values, if the column is ColumnData::Integer.

§Returns
  • Some(&Array1<i64>) - the values, one per sample.
  • None - if the column holds another variant.
Source

pub fn as_string(&self) -> Option<&Array1<String>>

The values, if the column is ColumnData::String.

§Returns
  • Some(&Array1<String>) - the values, one per sample.
  • None - if the column holds another variant.
Source

pub fn as_bytes(&self) -> Option<&Array2<u8>>

The values, if the column is ColumnData::Bytes.

§Returns
  • Some(&Array2<u8>) - the rows, one per sample.
  • None - if the column holds another variant.
Source

pub fn to_numeric(&self) -> Option<Array1<f64>>

The values as f64, one per sample.

§Returns
§Notes

An i64 above 2^53 loses precision as an f64.

Trait Implementations§

Source§

impl Clone for Column

Source§

fn clone(&self) -> Column

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Column

Source§

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

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

impl PartialEq for Column

Source§

fn eq(&self, other: &Column) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Column

Auto Trait Implementations§

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> Same for T

Source§

type Output = T

Should always be Self
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, 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.