refactor: update documentation to use "Quantamental DataFrame" terminology

This commit is contained in:
Palash Tyagi 2024-11-19 00:26:51 +00:00
parent 6c6a656efb
commit e9d53e48f7

View File

@ -6,7 +6,7 @@ use polars::datatypes::DataType;
use polars::prelude::*; use polars::prelude::*;
use std::error::Error; use std::error::Error;
/// Check if a DataFrame is a quantamental DataFrame. /// Check if a DataFrame is a Quantamental DataFrame.
/// A standard Quantamental DataFrame has the following columns: /// A standard Quantamental DataFrame has the following columns:
/// - `real_date`: Date column as a date type /// - `real_date`: Date column as a date type
/// - `cid`: Column of cross-sectional identifiers /// - `cid`: Column of cross-sectional identifiers
@ -30,9 +30,9 @@ pub fn check_quantamental_dataframe(df: &DataFrame) -> Result<(), Box<dyn Error>
Ok(()) Ok(())
} }
/// Check if a DataFrame is a quantamental DataFrame. /// Check if a DataFrame is a Quantamental DataFrame.
/// Returns true if the DataFrame is a quantamental DataFrame, false otherwise. /// Returns true if the DataFrame is a Quantamental DataFrame, false otherwise.
/// Uses the `check_quantamental_dataframe` function to check if the DataFrame is a quantamental DataFrame. /// Uses the `check_quantamental_dataframe` function to check if the DataFrame is a Quantamental DataFrame.
pub fn is_quantamental_dataframe(df: &DataFrame) -> bool { pub fn is_quantamental_dataframe(df: &DataFrame) -> bool {
check_quantamental_dataframe(df).is_ok() check_quantamental_dataframe(df).is_ok()
} }
@ -75,7 +75,7 @@ pub fn sort_qdf_columns(qdf: &mut DataFrame) -> Result<(), Box<dyn Error>> {
Ok(()) Ok(())
} }
/// Get intersecting cross-sections from a DataFrame. /// Get intersecting cross-sections from a Quantamental DataFrame.
pub fn get_intersecting_cids( pub fn get_intersecting_cids(
df: &DataFrame, df: &DataFrame,
xcats: &Option<Vec<String>>, xcats: &Option<Vec<String>>,
@ -89,7 +89,7 @@ pub fn get_intersecting_cids(
Ok(keep_cids) Ok(keep_cids)
} }
/// Get intersecting tickers from a DataFrame. /// Get intersecting tickers from a Quantamental DataFrame.
#[allow(dead_code)] #[allow(dead_code)]
fn get_tickers_interesecting_on_xcat( fn get_tickers_interesecting_on_xcat(
df: &DataFrame, df: &DataFrame,
@ -123,21 +123,40 @@ pub fn get_ticker_column_for_quantamental_dataframe(
.clone()) .clone())
} }
/// Get the unique tickers from a DataFrame. /// Get the unique tickers from a Quantamental DataFrame.
/// Returns a Vec of unique tickers. /// Returns a Vec of unique tickers.
pub fn get_unique_tickers(df: &DataFrame) -> Result<Vec<String>, Box<dyn Error>> { pub fn get_unique_tickers(df: &DataFrame) -> Result<Vec<String>, Box<dyn Error>> {
let ticker_col = get_ticker_column_for_quantamental_dataframe(df)?; let ticker_col = get_ticker_column_for_quantamental_dataframe(df)?;
_get_unique_strs_from_str_column_object(&ticker_col) _get_unique_strs_from_str_column_object(&ticker_col)
} }
/// Get the unique cross-sectional identifiers (`cids`) from a DataFrame. /// Get the unique cross-sectional identifiers (`cids`) from a Quantamental DataFrame.
pub fn get_unique_cids(df: &DataFrame) -> Result<Vec<String>, Box<dyn Error>> { pub fn get_unique_cids(df: &DataFrame) -> Result<Vec<String>, Box<dyn Error>> {
check_quantamental_dataframe(df)?; check_quantamental_dataframe(df)?;
get_unique_from_str_column(df, "cid") get_unique_from_str_column(df, "cid")
} }
/// Get the unique extended categories (`xcats`) from a DataFrame. /// Get the unique extended categories (`xcats`) from a Quantamental DataFrame.
pub fn get_unique_xcats(df: &DataFrame) -> Result<Vec<String>, Box<dyn Error>> { pub fn get_unique_xcats(df: &DataFrame) -> Result<Vec<String>, Box<dyn Error>> {
check_quantamental_dataframe(df)?; check_quantamental_dataframe(df)?;
get_unique_from_str_column(df, "xcat") get_unique_from_str_column(df, "xcat")
} }
/// Get the unique dates as a polars Column from a Quantamental DataFrame.
pub fn get_unique_dates(df: &DataFrame) -> Result<Column, Box<dyn Error>> {
let date_col = df.column("real_date")?;
let unique_dates = date_col.unique()?.sort(SortOptions::default())?;
Ok(unique_dates)
}