refactor: rename apply_blacklist_lazy to apply_blacklist and update documentation

This commit is contained in:
Palash Tyagi 2025-04-21 01:35:40 +01:00
parent 0e4d58a9d8
commit 1275e7c2c9

View File

@ -22,21 +22,41 @@ impl Blacklist {
} }
} }
/// Apply a blacklist to a Quantamental DataFrame with Lazy API. /// Apply a blacklist to a Quantamental DataFrame.
/// ///
/// * `blacklist` is a map from any “tickerlike” key to a tuple of /// * `blacklist` is a map from any “tickerlike” key to a tuple of
/// `(start_date, end_date)` in **inclusive** `"YYYYMMDD"` format. /// `(start_date, end_date)` in **inclusive** `"YYYYMMDD"` format.
/// * `metrics` if `None`, every metric from `get_unique_metrics(df)` /// * `metrics` if `None`, every metric from `get_unique_metrics(df)`
/// is used. /// is used.
/// * `group_by_cid = Some(false)` is not implemented yet (parity with /// * `group_by_cid = Some(false)` is not implemented yet.
/// the eager version). pub fn apply_blacklist(
pub fn apply_blacklist_lazy(
df: &mut DataFrame, df: &mut DataFrame,
blacklist: &BTreeMap<String, (String, String)>, blacklist: &BTreeMap<String, (String, String)>,
metrics: Option<Vec<String>>, metrics: Option<Vec<String>>,
group_by_cid: Option<bool>, group_by_cid: Option<bool>,
) -> Result<DataFrame, Box<dyn std::error::Error>> { ) -> Result<DataFrame, Box<dyn std::error::Error>> {
check_quantamental_dataframe(df)?; check_quantamental_dataframe(df)?;
// dataframe is like:
// | cid | xcat | real_date | metric1 | metric2 |
// |-----|------|-----------|---------|---------|
// | A | B | 2023-01-01| 1.0 | 2.0 |
// | A | B | 2023-01-02| 1.0 | 2.0 |
// | A | C | 2023-01-01| 1.0 | 2.0 |
// | A | C | 2023-01-02| 1.0 | 2.0 |
// | D | E | 2023-01-01| 1.0 | 2.0 |
// | D | E | 2023-01-02| 1.0 | 2.0 |
// (real date column is Naive date)
// blacklist is like:
// {'A_B_1': ('2023-01-02', '2023-01-03'),
// 'A_B_2': ('2023-01-04', '2023-01-05'),
// 'A_C_1': ('2023-01-02', '2023-01-03'), }
// get_cid('A_B_1') = 'A'
// get_cid('A_B_2') = 'A'
// get_cid('D_E_1') = 'D'
Ok(df.clone()) Ok(df.clone())
} }
/// Create a blacklist from a Quantamental DataFrame. /// Create a blacklist from a Quantamental DataFrame.