adding filter layer to jpmaqsdownload

This commit is contained in:
Palash Tyagi
2024-11-17 05:12:21 +00:00
parent d4721a0b79
commit 41e544d5bf
6 changed files with 184 additions and 98 deletions

View File

@@ -106,7 +106,7 @@ fn _load_qdf_thread_safe(file_path: &str) -> Result<DataFrame, Box<dyn Error + S
.into()
})
}
pub fn load_quantamental_dataframe_from_download_bank(
pub fn load_qdf_from_download_bank(
folder_path: &str,
cids: Option<Vec<&str>>,
xcats: Option<Vec<&str>>,

View File

@@ -17,8 +17,8 @@ const QDF_INDEX_COLUMNS: [&str; 3] = ["real_date", "cid", "xcat"];
/// If no filters are provided, the original DataFrame is returned.
pub fn reduce_dataframe(
df: DataFrame,
cids: Option<Vec<String>>,
xcats: Option<Vec<String>>,
cids: Option<Vec<&str>>,
xcats: Option<Vec<&str>>,
metrics: Option<Vec<String>>,
start: Option<&str>,
end: Option<&str>,
@@ -36,8 +36,10 @@ pub fn reduce_dataframe(
let u_xcats: Vec<String> = get_unique_xcats(&new_df)?;
let u_tickers: Vec<String> = _get_unique_strs_from_str_column_object(&ticker_col)?;
let specified_cids: Vec<String> = cids.unwrap_or_else(|| u_cids.clone());
let specified_xcats: Vec<String> = xcats.unwrap_or_else(|| u_xcats.clone());
let specified_cids: Vec<&str> =
cids.unwrap_or_else(|| u_cids.iter().map(AsRef::as_ref).collect());
let specified_xcats: Vec<&str> =
xcats.unwrap_or_else(|| u_xcats.iter().map(AsRef::as_ref).collect());
let non_idx_cols: Vec<String> = new_df
.get_column_names()
@@ -63,8 +65,17 @@ pub fn reduce_dataframe(
let keep_tickers: Vec<String> = match intersect {
// true => get_intersecting_cids_str_func(&specified_cids, &specified_xcats, &u_tickers),
true => {
let int_cids =
get_intersecting_cids_str_func(&specified_cids, &specified_xcats, &u_tickers);
let int_cids = get_intersecting_cids_str_func(
&specified_cids
.iter()
.map(|&s| s.to_string())
.collect::<Vec<String>>(),
&specified_xcats
.iter()
.map(|&s| s.to_string())
.collect::<Vec<String>>(),
&u_tickers,
);
create_interesecting_tickers(
&int_cids.iter().map(AsRef::as_ref).collect::<Vec<&str>>(),
&specified_xcats