Skip to content

Commit a47dfe1

Browse files
committed
update pyo3/polars
1 parent c6c1827 commit a47dfe1

File tree

5 files changed

+26
-29
lines changed

5 files changed

+26
-29
lines changed

Cargo.toml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "_utils_rust"
33
version = "0.1.0"
44
edition = "2021"
5-
rust-version = "1.76.0"
5+
rust-version = "1.85.0"
66

77
[lib]
88
name = "_utils_rust"
@@ -15,10 +15,10 @@ itertools = { version = "0.12.1" }
1515
ndarray = { version = "0.15.6", features = ["rayon"] }
1616
ndarray-stats = { version = "0.5.1" }
1717
num = { version = "0.4.1" }
18-
numpy = { version = "0.21" }
19-
polars = { version = "0.44", features = ["partition_by", "dtype-categorical"] }
20-
polars-arrow = { version = "0.44" }
21-
pyo3 = { version = "0.21", features = ["extension-module"] }
22-
pyo3-polars = { version = "0.18", features = ["dtype-categorical"] }
18+
numpy = { version = "0.24" }
19+
polars = { version = "0.48", features = ["partition_by", "dtype-categorical"] }
20+
polars-arrow = { version = "0.48" }
21+
pyo3 = { version = "0.24.2", features = ["extension-module"] }
22+
pyo3-polars = { version = "0.21", features = ["dtype-categorical"] }
2323
rayon = { version = "1.8" }
2424
sprs = { version = "= 0.11.1", features = ["serde"] }

src/coordinates.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ pub fn coordinate_as_string<'py>(
2020
n_threads: Option<usize>,
2121
) -> PyResult<Bound<'py, PyArray1<PyFixedString<12>>>> {
2222
match string_coordinate_index_(x.as_array(), y.as_array(), n_threads) {
23-
Ok(string_coordinates) => Ok(string_coordinates
24-
.map(|s| (*s).into())
25-
.into_pyarray_bound(py)),
23+
Ok(string_coordinates) => Ok(string_coordinates.map(|s| (*s).into()).into_pyarray(py)),
2624
Err(e) => Err(PyRuntimeError::new_err(e.to_string())),
2725
}
2826
}
@@ -40,10 +38,7 @@ pub fn categorical_coordinate<'py>(
4038
Bound<'py, PyArray2<CoordInt>>,
4139
)> {
4240
match categorical_coordinate_(x.as_array(), y.as_array(), n_threads) {
43-
Ok((codes, coordinates)) => Ok((
44-
codes.into_pyarray_bound(py),
45-
coordinates.into_pyarray_bound(py),
46-
)),
41+
Ok((codes, coordinates)) => Ok((codes.into_pyarray(py), coordinates.into_pyarray(py))),
4742
Err(e) => Err(PyRuntimeError::new_err(e.to_string())),
4843
}
4944
}

src/cosine.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ macro_rules! build_cos_ct_fn {
5656

5757
match cos_ct {
5858
Ok((cosine, score, celltype_map)) => Ok((
59-
cosine.into_pyarray_bound(py),
60-
score.into_pyarray_bound(py),
61-
celltype_map.into_pyarray_bound(py),
59+
cosine.into_pyarray(py),
60+
score.into_pyarray(py),
61+
celltype_map.into_pyarray(py),
6262
)),
6363
Err(e) => Err(PyValueError::new_err(e.to_string())),
6464
}

src/gridcounts.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ impl GridCounts {
281281

282282
fn __getstate__<'py>(&self, py: Python<'py>) -> PyResult<Bound<'py, PyBytes>> {
283283
match serialize(&(&self.counts, self.shape, self.resolution, self.n_threads)) {
284-
Ok(bytes) => Ok(PyBytes::new_bound(py, &bytes)),
284+
Ok(bytes) => Ok(PyBytes::new(py, &bytes)),
285285
Err(e) => Err(PyRuntimeError::new_err(e.to_string())),
286286
}
287287
}
@@ -379,7 +379,7 @@ impl GridCounts {
379379
});
380380

381381
let gridcounts = triplet_to_dense(TriMatI::from_triplets(self.shape, i, j, v));
382-
Python::with_gil(|py| gridcounts.into_pyarray_bound(py).unbind())
382+
Python::with_gil(|py| gridcounts.into_pyarray(py).unbind())
383383
}
384384

385385
fn select_genes(&mut self, genes: HashSet<String>) {

src/sparsearray_conversion.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ static SPMATRIX: GILOnceCell<Py<PyAny>> = GILOnceCell::new();
2222
pub struct WrappedCsx<N, I: SpIndex, Iptr: SpIndex>(pub CsMatI<N, I, Iptr>);
2323

2424
fn get_scipy_sparse(py: Python) -> PyResult<&Py<PyModule>> {
25-
SP_SPARSE.get_or_try_init(py, || Ok(py.import_bound("scipy.sparse")?.unbind()))
25+
SP_SPARSE.get_or_try_init(py, || Ok(py.import("scipy.sparse")?.unbind()))
2626
}
2727

2828
fn get_scipy_sparse_attr(py: Python, attr: &str) -> PyResult<PyObject> {
@@ -46,16 +46,20 @@ where
4646
let (indptr, indices, data) = cs.into_raw_storage();
4747

4848
return (
49-
data.into_pyarray_bound(py),
50-
indices.into_pyarray_bound(py),
51-
indptr.into_pyarray_bound(py),
49+
data.into_pyarray(py),
50+
indices.into_pyarray(py),
51+
indptr.into_pyarray(py),
5252
);
5353
}
5454

55-
impl<N: Element, I: SpIndex + Element, Iptr: SpIndex + Element> IntoPy<PyObject>
55+
impl<'py, N: Element, I: SpIndex + Element, Iptr: SpIndex + Element> IntoPyObject<'py>
5656
for WrappedCsx<N, I, Iptr>
5757
{
58-
fn into_py(self, py: Python<'_>) -> PyObject {
58+
type Target = PyAny;
59+
type Output = Bound<'py, Self::Target>;
60+
type Error = PyErr; // TODO: propagate better errors?
61+
62+
fn into_pyobject(self, py: Python<'py>) -> Result<Self::Output, Self::Error> {
5963
let csx = self.0;
6064
let shape = csx.shape();
6165

@@ -67,16 +71,14 @@ impl<N: Element, I: SpIndex + Element, Iptr: SpIndex + Element> IntoPy<PyObject>
6771
sparray
6872
.unwrap()
6973
.call1(py, (make_csx_tuple(py, csx), shape))
70-
.unwrap()
71-
.extract(py)
72-
.unwrap()
74+
.map(move |x| x.into_bound(py))
7375
}
7476
}
75-
impl<'py, N: Element, I: SpIndex + Element, Iptr: SpIndex + Element> FromPyObject<'py>
77+
impl<'py, N: Element + Clone, I: SpIndex + Element, Iptr: SpIndex + Element> FromPyObject<'py>
7678
for WrappedCsx<N, I, Iptr>
7779
{
7880
fn extract_bound(obj: &Bound<'py, PyAny>) -> PyResult<Self> {
79-
fn boundpyarray_to_vec<T: Element>(obj: Bound<'_, PyAny>) -> PyResult<Vec<T>> {
81+
fn boundpyarray_to_vec<T: Element + Clone>(obj: Bound<'_, PyAny>) -> PyResult<Vec<T>> {
8082
Ok(obj.extract::<PyReadonlyArray1<T>>()?.as_array().to_vec())
8183
}
8284

0 commit comments

Comments
 (0)