diff --git a/src/frame/base.rs b/src/frame/base.rs index 97552cc..cee61bb 100644 --- a/src/frame/base.rs +++ b/src/frame/base.rs @@ -1,3 +1,19 @@ +//! Core data-frame structures such as [`Frame`] and [`RowIndex`]. +//! +//! The [`Frame`] type stores column-labelled data with an optional row index +//! and builds upon the [`crate::matrix::Matrix`] type. +//! +//! # Examples +//! +//! ``` +//! use rustframe::frame::{Frame, RowIndex}; +//! use rustframe::matrix::Matrix; +//! +//! let data = Matrix::from_cols(vec![vec![1, 2], vec![3, 4]]); +//! let frame = Frame::new(data, vec!["L", "R"], Some(RowIndex::Int(vec![10, 20]))); +//! assert_eq!(frame.columns(), &["L", "R"]); +//! assert_eq!(frame.index(), &RowIndex::Int(vec![10, 20])); +//! ``` use crate::matrix::Matrix; use chrono::NaiveDate; use std::collections::HashMap; diff --git a/src/frame/mod.rs b/src/frame/mod.rs index ced467c..e5e94b0 100644 --- a/src/frame/mod.rs +++ b/src/frame/mod.rs @@ -1,3 +1,21 @@ +//! High-level interface for working with columnar data and row indices. +//! +//! The [`Frame`](crate::frame::Frame) type combines a matrix with column labels and a typed row +//! index, similar to data frames in other data-analysis libraries. +//! +//! # Examples +//! +//! ``` +//! use rustframe::frame::{Frame, RowIndex}; +//! use rustframe::matrix::Matrix; +//! +//! // Build a frame from two columns labelled "A" and "B". +//! let data = Matrix::from_cols(vec![vec![1.0, 2.0], vec![3.0, 4.0]]); +//! let frame = Frame::new(data, vec!["A", "B"], None); +//! +//! assert_eq!(frame["A"], vec![1.0, 2.0]); +//! assert_eq!(frame.index(), &RowIndex::Range(0..2)); +//! ``` pub mod base; pub mod ops; diff --git a/src/frame/ops.rs b/src/frame/ops.rs index 1c3254b..6030ce1 100644 --- a/src/frame/ops.rs +++ b/src/frame/ops.rs @@ -1,3 +1,16 @@ +//! Trait implementations that allow [`Frame`] to reuse matrix operations. +//! +//! These modules forward numeric and boolean aggregation methods from the +//! underlying [`Matrix`](crate::matrix::Matrix) type so that they can be called +//! directly on a [`Frame`]. +//! +//! ``` +//! use rustframe::frame::Frame; +//! use rustframe::matrix::{Matrix, SeriesOps}; +//! +//! let frame = Frame::new(Matrix::from_cols(vec![vec![1.0, 2.0]]), vec!["A"], None); +//! assert_eq!(frame.sum_vertical(), vec![3.0]); +//! ``` use crate::frame::Frame; use crate::matrix::{Axis, BoolMatrix, BoolOps, FloatMatrix, SeriesOps};