Skip to content

Commit

Permalink
⬆️ Bump pyo3 from 0.20.3 to 0.21.1, numpy from 0.20.0 to 0.21.0 (#15)
Browse files Browse the repository at this point in the history
* ⬆️ Bump pyo3 from 0.20.3 to 0.21.1, numpy from 0.20.0 to 0.21.0

Bumps [pyo3](https://github.com/pyo3/pyo3) from 0.20.3 to 0.21.1.
- [Release notes](https://github.com/pyo3/pyo3/releases)
- [Changelog](https://github.com/PyO3/pyo3/blob/main/CHANGELOG.md)
- [Commits](PyO3/pyo3@v0.20.3...v0.21.1)

Bumps [numpy](https://github.com/PyO3/rust-numpy) from 0.20.0 to 0.21.0.
- [Release notes](https://github.com/PyO3/rust-numpy/releases)
- [Changelog](https://github.com/PyO3/rust-numpy/blob/main/CHANGELOG.md)
- [Commits](PyO3/rust-numpy@v0.20.0...v0.21.0)

* 👽 Migrate to pyo3's new Bound API

Switch from pyo3 GIL Ref API to the Bound API. Xref https://polar.sh/davidhewitt/posts/replacing-pyo3-api-pt1 and https://pyo3.rs/v0.21.1/migration#from-020-to-021
  • Loading branch information
weiji14 authored Apr 7, 2024
1 parent 0f5df6e commit 33285da
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 20 deletions.
24 changes: 12 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ crate-type = ["cdylib"]
bytes = "1.5.0"
geo = "0.28.0"
ndarray = "0.15.6"
numpy = "0.20.0"
numpy = "0.21.0"
object_store = { version = "0.9.0", features = ["http"] }
pyo3 = { version = "0.20.3", features = ["abi3-py310", "extension-module"] }
pyo3 = { version = "0.21.1", features = ["abi3-py310", "extension-module"] }
tiff = { git = "https://github.com/image-rs/image-tiff.git", version = "0.9.1", rev = "0c54a18e2130bd8e3e897009e1fb59eaaf607c6c" } # https://github.com/image-rs/image-tiff/pull/224
tokio = { version = "1.36.0", features = ["rt-multi-thread"] }
url = "2.5.0"
Expand Down
11 changes: 5 additions & 6 deletions src/python/adapters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ use numpy::{PyArray3, ToPyArray};
use object_store::{parse_url, ObjectStore};
use pyo3::exceptions::{PyBufferError, PyFileNotFoundError, PyValueError};
use pyo3::prelude::{pyclass, pyfunction, pymethods, pymodule, PyModule, PyResult, Python};
use pyo3::wrap_pyfunction;
use pyo3::PyErr;
use pyo3::{wrap_pyfunction, Bound, PyErr};
use url::Url;

use crate::io::geotiff::CogReader;
Expand Down Expand Up @@ -60,14 +59,14 @@ impl PyCogReader {
/// -------
/// array : np.ndarray
/// 3D array of shape (band, height, width) containing the GeoTIFF pixel data.
fn to_numpy<'py>(&mut self, py: Python<'py>) -> PyResult<&'py PyArray3<f32>> {
fn to_numpy<'py>(&mut self, py: Python<'py>) -> PyResult<Bound<'py, PyArray3<f32>>> {
let array_data: Array3<f32> = self
.inner
.ndarray()
.map_err(|err| PyValueError::new_err(err.to_string()))?;

// Convert from ndarray (Rust) to numpy ndarray (Python)
Ok(array_data.to_pyarray(py))
Ok(array_data.to_pyarray_bound(py))
}
}

Expand Down Expand Up @@ -124,7 +123,7 @@ fn path_to_stream(path: &str) -> PyResult<Cursor<Bytes>> {
/// assert array.shape == (20, 20)
#[pyfunction]
#[pyo3(name = "read_geotiff")]
fn read_geotiff_py<'py>(path: &str, py: Python<'py>) -> PyResult<&'py PyArray3<f32>> {
fn read_geotiff_py<'py>(path: &str, py: Python<'py>) -> PyResult<Bound<'py, PyArray3<f32>>> {
// Open URL with TIFF decoder
let mut reader = PyCogReader::new(path)?;

Expand All @@ -138,7 +137,7 @@ fn read_geotiff_py<'py>(path: &str, py: Python<'py>) -> PyResult<&'py PyArray3<f
/// the `lib.name` setting in the `Cargo.toml`, else Python will not be able to
/// import the module.
#[pymodule]
fn cog3pio(_py: Python, m: &PyModule) -> PyResult<()> {
fn cog3pio<'py>(_py: Python, m: &Bound<'py, PyModule>) -> PyResult<()> {
// Register Python classes
m.add_class::<PyCogReader>()?;
// Register Python functions
Expand Down

0 comments on commit 33285da

Please sign in to comment.