Add Python wrapper for utils module and update msyrs.pyi to include utils functions

This commit is contained in:
Palash Tyagi 2025-04-10 23:26:49 +01:00
parent 4df2d4147d
commit c0f7299643
3 changed files with 38 additions and 5 deletions

View File

@ -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(())
}

22
src/_py/utils.rs Normal file
View File

@ -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<String>,
) -> PyResult<PySeries> {
Ok(PySeries(
crate::utils::dateutils::get_bdates_series_default(start_date, end_date, freq)
.map_err(|e| PyErr::new::<pyo3::exceptions::PyValueError, _>(format!("{}", e)))?,
))
}

View File

@ -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: ...
class utils:
__all__ = ["get_bdates_series_default"]
@staticmethod
def get_bdates_series_default(*args, **kwargs) -> Series: ...