mirror of
https://github.com/Magnus167/msyrs.git
synced 2025-08-20 04:20:00 +00:00
refactor: update documentation to use "Quantamental DataFrame" terminology
This commit is contained in:
parent
6c6a656efb
commit
e9d53e48f7
@ -6,7 +6,7 @@ use polars::datatypes::DataType;
|
||||
use polars::prelude::*;
|
||||
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:
|
||||
/// - `real_date`: Date column as a date type
|
||||
/// - `cid`: Column of cross-sectional identifiers
|
||||
@ -30,9 +30,9 @@ pub fn check_quantamental_dataframe(df: &DataFrame) -> Result<(), Box<dyn Error>
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Check if a DataFrame is a quantamental DataFrame.
|
||||
/// 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.
|
||||
/// Check if a DataFrame is a Quantamental DataFrame.
|
||||
/// 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.
|
||||
pub fn is_quantamental_dataframe(df: &DataFrame) -> bool {
|
||||
check_quantamental_dataframe(df).is_ok()
|
||||
}
|
||||
@ -75,7 +75,7 @@ pub fn sort_qdf_columns(qdf: &mut DataFrame) -> Result<(), Box<dyn Error>> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Get intersecting cross-sections from a DataFrame.
|
||||
/// Get intersecting cross-sections from a Quantamental DataFrame.
|
||||
pub fn get_intersecting_cids(
|
||||
df: &DataFrame,
|
||||
xcats: &Option<Vec<String>>,
|
||||
@ -89,7 +89,7 @@ pub fn get_intersecting_cids(
|
||||
Ok(keep_cids)
|
||||
}
|
||||
|
||||
/// Get intersecting tickers from a DataFrame.
|
||||
/// Get intersecting tickers from a Quantamental DataFrame.
|
||||
#[allow(dead_code)]
|
||||
fn get_tickers_interesecting_on_xcat(
|
||||
df: &DataFrame,
|
||||
@ -123,21 +123,40 @@ pub fn get_ticker_column_for_quantamental_dataframe(
|
||||
.clone())
|
||||
}
|
||||
|
||||
/// Get the unique tickers from a DataFrame.
|
||||
/// Get the unique tickers from a Quantamental DataFrame.
|
||||
/// Returns a Vec of unique tickers.
|
||||
pub fn get_unique_tickers(df: &DataFrame) -> Result<Vec<String>, Box<dyn Error>> {
|
||||
let ticker_col = get_ticker_column_for_quantamental_dataframe(df)?;
|
||||
_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>> {
|
||||
check_quantamental_dataframe(df)?;
|
||||
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>> {
|
||||
check_quantamental_dataframe(df)?;
|
||||
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)
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user