[Python] pyo3 multiple `wrap` found

Discussão em 'Python' iniciado por Stack, Fevereiro 22, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to return a HashMap<String, Vec<Vec<f64>>> from Rust to Python.

    This is the function in PyO3 wrapper:

    pub fn predict_intervals<'py>(
    &self,
    py: Python<'py>,
    flat_data: PyReadonlyArray1<f64>,
    rows: usize,
    cols: usize,
    parallel: Option<bool>,
    ) -> PyResult<Bound<'py, PyDict<String, PyArray2<f64>>>> {
    let flat_data = flat_data.as_slice()?;
    let data = Matrix::new(flat_data, rows, cols);
    let parallel = parallel.unwrap_or(true);

    let predictions: HashMap<String, Vec<Vec<f64>>> = self.booster.predict_intervals(&data, parallel); // Result<YourPredictionType, YourErrorType>

    let py_dict: PyDict<String, PyArray2<f64>> = PyDict::new(py);
    for (key, value) in predictions?.iter() {
    let py_array: PyArray2<f64> = PyArray2::from_array(py, value); // Convert each value to PyArray2
    py_dict.set_item(key, py_array)?; // Add to the dictionary
    }

    Ok(py_dict.into_py_dict_bound(py))
    }


    But, I keep getting the following error:

    error[E0034]: multiple applicable items in scope
    --> src\booster.rs:312:10
    |
    312 | ) -> PyResult<Bound<'py, PyDict<String, PyArray2<f64>>>> {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ multiple `wrap` found
    |
    = note: candidate #1 is defined in an impl for the type `IntoPyConverter<Result<T, E>>`
    = note: candidate #2 is defined in an impl for the type `IntoPyConverter<T>`
    = note: candidate #3 is defined in an impl for the type `IntoPyObjectConverter<Result<T, E>>`
    = note: candidate #4 is defined in an impl for the type `IntoPyObjectConverter<T>`
    = note: and 2 others


    How can I solve this problem?

    Continue reading...

Compartilhe esta Página