From e9d53e48f7d91f7fa7e01021f5e84641ca424c4a Mon Sep 17 00:00:00 2001 From: Palash Tyagi <23239946+Magnus167@users.noreply.github.com> Date: Tue, 19 Nov 2024 00:26:51 +0000 Subject: [PATCH] refactor: update documentation to use "Quantamental DataFrame" terminology --- src/utils/qdf/core.rs | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/src/utils/qdf/core.rs b/src/utils/qdf/core.rs index 1070deb..38eec71 100644 --- a/src/utils/qdf/core.rs +++ b/src/utils/qdf/core.rs @@ -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 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> { 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>, @@ -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, Box> { 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, Box> { 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, Box> { 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> { + let date_col = df.column("real_date")?; + let unique_dates = date_col.unique()?.sort(SortOptions::default())?; + Ok(unique_dates) +} + + + + + + + + + + + +