use numpy::PyReadonlyArrayDyn;
use pyo3::{exceptions::PyException, prelude::*};
use crate::Forecast;
#[derive(Debug)]
#[pyclass]
pub struct AutoETS {
inner: augurs_ets::AutoETS,
}
#[pymethods]
impl AutoETS {
#[new]
#[allow(clippy::too_many_arguments)]
pub fn new(season_length: usize, spec: String) -> PyResult<Self> {
let inner = augurs_ets::AutoETS::new(season_length, spec.as_str())
.map_err(|e| PyException::new_err(e.to_string()))?;
Ok(Self { inner })
}
fn __repr__(&self) -> String {
format!(
"AutoETS(spec=\"{}\", season_length={})",
self.inner.spec(),
self.inner.season_length()
)
}
pub fn fit(&mut self, y: PyReadonlyArrayDyn<'_, f64>) -> PyResult<()> {
self.inner
.fit(y.as_slice()?)
.map_err(|e| PyException::new_err(e.to_string()))?;
Ok(())
}
pub fn predict(&self, horizon: usize, level: Option<f64>) -> PyResult<Forecast> {
self.inner
.predict(horizon, level)
.map(Forecast::from)
.map_err(|e| PyException::new_err(e.to_string()))
}
pub fn predict_in_sample(&self, level: Option<f64>) -> PyResult<Forecast> {
self.inner
.predict_in_sample(level)
.map(Forecast::from)
.map_err(|e| PyException::new_err(e.to_string()))
}
}