numcodecs_python/utils.rs
1use numpy::PyUntypedArray;
2use pyo3::{prelude::*, sync::GILOnceCell};
3
4pub fn numpy_asarray<'py>(
5 py: Python<'py>,
6 a: Borrowed<'_, 'py, PyAny>,
7) -> Result<Bound<'py, PyUntypedArray>, PyErr> {
8 static AS_ARRAY: GILOnceCell<Py<PyAny>> = GILOnceCell::new();
9
10 let as_array = AS_ARRAY.import(py, "numpy", "asarray")?;
11
12 as_array.call1((a,))?.extract()
13}