Skip to main content

SchemaSummary

Struct SchemaSummary 

Source
pub struct SchemaSummary {
    pub rows: usize,
    pub columns: usize,
    /* private fields */
}
Expand description

A small, displayable description of a Table’s columns.

Fields§

§rows: usize

Number of data rows.

§columns: usize

Number of columns.

Implementations§

Source§

impl SchemaSummary

Source

pub fn column_summaries(&self) -> &[ColumnSummary]

Per-column summaries, in column order.

Examples found in repository?
examples/data_06_visual_readiness_summary.rs (line 15)
12fn print_schema(summary: &matten_data::SchemaSummary) {
13    println!("rows             {}", summary.rows);
14    println!("columns          {}", summary.columns);
15    for col in summary.column_summaries() {
16        println!(
17            "column {:<8} kind={:<7} missing={}",
18            col.name, col.kind, col.missing
19        );
20    }
21}
22
23fn main() -> Result<(), MattenDataError> {
24    let csv = "\
25region,sales,cost,note
26north,100,40,ok
27south,150,,review
28east,120,55,ok";
29
30    let table = Table::from_csv_str(csv)?;
31    let source = table.schema_summary();
32
33    println!("== Source table ==");
34    println!("source columns   {:?}", table.column_names());
35    print_schema(&source);
36    assert_eq!(table.column_names(), &["region", "sales", "cost", "note"]);
37    assert_eq!(source.rows, 3);
38    assert_eq!(source.columns, 4);
39    assert_eq!(
40        source
41            .column_summaries()
42            .iter()
43            .find(|col| col.name == "cost")
44            .map(|col| col.missing),
45        Some(1)
46    );
47
48    println!();
49    println!("== Selection ==");
50    let selected = table.select_columns(["sales", "cost"])?;
51    println!("selected columns {:?}", selected.column_names());
52    println!("left out         [\"region\", \"note\"]");
53    assert_eq!(selected.column_names(), &["sales", "cost"]);
54
55    match selected.try_numeric() {
56        Err(MattenDataError::MissingValue { column, row }) => {
57            println!("strict numeric   Err: missing column={column}, csv_line={row}");
58            assert_eq!(column, "cost");
59            assert_eq!(row, 3);
60        }
61        other => panic!("expected MissingValue, got {other:?}"),
62    }
63
64    println!();
65    println!("== Explicit cleanup ==");
66    let filled = selected.fill_missing(0.0)?;
67    let numeric = filled.try_numeric()?;
68    println!("numeric rows     {}", numeric.row_count());
69    println!("numeric columns  {}", numeric.column_count());
70    println!("numeric names    {:?}", numeric.column_names());
71    assert_eq!(numeric.row_count(), 3);
72    assert_eq!(numeric.column_count(), 2);
73    assert_eq!(numeric.column_names(), &["sales", "cost"]);
74
75    let tensor = numeric.to_tensor()?;
76    println!("tensor shape     {:?}", tensor.shape());
77    println!("row-major values {:?}", tensor.as_slice());
78    assert_eq!(tensor.shape(), &[3, 2]);
79    assert_eq!(tensor.as_slice(), &[100.0, 40.0, 150.0, 0.0, 120.0, 55.0]);
80
81    println!();
82    println!("data_06_visual_readiness_summary: OK");
83    Ok(())
84}
More examples
Hide additional examples
examples/data_01_schema_summary.rs (line 39)
18fn main() -> Result<(), matten_data::MattenDataError> {
19    let csv = "\
20region,sales,cost,active
21north,100,40.5,true
22south,150,,true
23east,120,55.0,false";
24
25    let table = Table::from_csv_str(csv)?;
26
27    // Top-level shape of the table.
28    println!("rows    : {}", table.row_count());
29    println!("columns : {}", table.column_count());
30    println!("names   : {:?}", table.column_names());
31
32    // A printable, one-glance summary (Table: R rows x C columns, then a line
33    // per column with its inferred kind and missing count).
34    let summary = table.schema_summary();
35    print!("{summary}");
36
37    // The same information, per column, if you want to act on it in code.
38    println!("--- per-column ---");
39    for col in summary.column_summaries() {
40        println!(
41            "{:<8} kind={:<7} missing={}",
42            col.name, col.kind, col.missing
43        );
44    }
45
46    // The "cost" column has exactly one missing cell (south).
47    let cost = summary
48        .column_summaries()
49        .iter()
50        .find(|c| c.name == "cost")
51        .expect("cost column exists");
52    assert_eq!(cost.missing, 1);
53    assert_eq!(table.row_count(), 3);
54    assert_eq!(table.column_count(), 4);
55
56    println!("data_01_schema_summary: OK");
57    Ok(())
58}

Trait Implementations§

Source§

impl Clone for SchemaSummary

Source§

fn clone(&self) -> SchemaSummary

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 SchemaSummary

Source§

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

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

impl Display for SchemaSummary

Source§

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

Formats the value using the given formatter. Read more

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> 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.