From c0f7299643c6351450f973f26a43c7d28e1bed28 Mon Sep 17 00:00:00 2001 From: Palash Tyagi <23239946+Magnus167@users.noreply.github.com> Date: Thu, 10 Apr 2025 23:26:49 +0100 Subject: [PATCH] Add Python wrapper for utils module and update msyrs.pyi to include utils functions --- src/_py/mod.rs | 4 ++++ src/_py/utils.rs | 22 ++++++++++++++++++++++ src/msyrs.pyi | 17 ++++++++++++----- 3 files changed, 38 insertions(+), 5 deletions(-) create mode 100644 src/_py/utils.rs diff --git a/src/_py/mod.rs b/src/_py/mod.rs index 4b37399..f61ed8c 100644 --- a/src/_py/mod.rs +++ b/src/_py/mod.rs @@ -7,6 +7,9 @@ pub mod download; /// Python wrapper for [`crate::panel`]. pub mod panel; +/// Python wrapper for [`crate::utils`]. +pub mod utils; + use pyo3::{prelude::*, wrap_pymodule}; /// PyO3 bindings for the `msyrs` Python wrapper. @@ -16,5 +19,6 @@ pub fn msyrs(_py: Python, m: &PyModule) -> PyResult<()> { m.add_wrapped(wrap_pymodule!(qdf::qdf))?; m.add_wrapped(wrap_pymodule!(download::download))?; m.add_wrapped(wrap_pymodule!(panel::panel))?; + m.add_wrapped(wrap_pymodule!(utils::utils))?; Ok(()) } diff --git a/src/_py/utils.rs b/src/_py/utils.rs new file mode 100644 index 0000000..1799f1a --- /dev/null +++ b/src/_py/utils.rs @@ -0,0 +1,22 @@ +use pyo3::prelude::*; +use pyo3_polars::{PyDataFrame, PySeries}; + +/// Python wrapper for [`crate::utils::qdf`] module. +#[allow(deprecated)] +#[pymodule] +pub fn utils(_py: Python, m: &PyModule) -> PyResult<()> { + m.add_function(wrap_pyfunction!(get_bdates_series_default, m)?)?; + Ok(()) +} + +#[pyfunction] +pub fn get_bdates_series_default( + start_date: String, + end_date: String, + freq: Option, +) -> PyResult { + Ok(PySeries( + crate::utils::dateutils::get_bdates_series_default(start_date, end_date, freq) + .map_err(|e| PyErr::new::(format!("{}", e)))?, + )) +} diff --git a/src/msyrs.pyi b/src/msyrs.pyi index f84036e..df6b596 100644 --- a/src/msyrs.pyi +++ b/src/msyrs.pyi @@ -34,16 +34,23 @@ class qdf: def pivot_dataframe_by_ticker(*args, **kwargs) -> DataFrame: ... class panel: - __all__ = ["historic_vol"] + __all__ = [ + "historic_vol", + "get_bdates_from_col_hv", + "get_period_indices_hv", + "linear_composite", + ] @staticmethod def historic_vol(*args, **kwargs) -> DataFrame: ... - @staticmethod def get_bdates_from_col_hv(*args, **kwargs) -> Series: ... - @staticmethod def get_period_indices_hv(*args, **kwargs) -> Series: ... - @staticmethod - def linear_composite(*args, **kwargs) -> DataFrame: ... \ No newline at end of file + def linear_composite(*args, **kwargs) -> DataFrame: ... + +class utils: + __all__ = ["get_bdates_series_default"] + @staticmethod + def get_bdates_series_default(*args, **kwargs) -> Series: ...