Skip to content

Commit

Permalink
chore(deps): bump pyo3 0.20.3 -> 0.21.2 (#241)
Browse files Browse the repository at this point in the history
* chore(deps): bump pyo3 0.20.3 -> 0.21.2

Signed-off-by: Luka Peschke <luka.peschke@toucantoco.com>

* fix compilation errors

Signed-off-by: Luka Peschke <luka.peschke@toucantoco.com>

* fix deprecation warnings

Signed-off-by: Luka Peschke <luka.peschke@toucantoco.com>

* convert FromPyObject impls to new bounds API

Signed-off-by: Luka Peschke <luka.peschke@toucantoco.com>

---------

Signed-off-by: Luka Peschke <luka.peschke@toucantoco.com>
  • Loading branch information
lukapeschke committed Jul 1, 2024
1 parent 2147bb5 commit b93636e
Show file tree
Hide file tree
Showing 8 changed files with 118 additions and 99 deletions.
68 changes: 34 additions & 34 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 @@ -12,10 +12,10 @@ crate-type = ["cdylib"]
calamine = { version = "0.25.0", features = ["dates"] }
chrono = { version = "0.4.38", default-features = false }
# NOTE: "extension-module" is actually required, see comments on features below
pyo3 = { version = "0.20.3", features = ["abi3-py38"] }
pyo3 = { version = "0.21.2", features = ["abi3-py38"] }

[dependencies.arrow]
version = "51.0.0"
version = "52.0.0"
# There's a lot of stuff we don't want here, such as serde support
default-features = false
features = ["pyarrow"]
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[build-system]
requires = ["maturin>=1.3.2,<2.0"]
requires = ["maturin>=1.6.0,<2.0"]
build-backend = "maturin"

[project]
Expand All @@ -25,6 +25,7 @@ Issues = "https://github.com/ToucanToco/fastexcel"
[tool.maturin]
python-source = "python"
module-name = "fastexcel._fastexcel"
features = ["pyo3/extension-module"]

[tool.mypy]
python_version = "3.8"
Expand Down
34 changes: 21 additions & 13 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@ mod types;
mod utils;

use error::{py_errors, ErrorContext};
use pyo3::prelude::*;
use pyo3::{prelude::*, types::PyString};
use types::python::{excelsheet::column_info::ColumnInfo, ExcelReader, ExcelSheet};

/// Reads an excel file and returns an object allowing to access its sheets and a bit of metadata
#[pyfunction]
fn read_excel(source: &PyAny) -> PyResult<ExcelReader> {
fn read_excel(source: &Bound<'_, PyAny>) -> PyResult<ExcelReader> {
use py_errors::IntoPyResult;

if let Ok(path) = source.extract::<&str>() {
if let Ok(path) = source.extract::<&PyString>() {
let path = path.to_str()?;
ExcelReader::try_from_path(path)
.with_context(|| format!("could not load excel file at {path}"))
.into_pyresult()
Expand Down Expand Up @@ -39,7 +40,8 @@ fn get_version() -> String {
}

#[pymodule]
fn _fastexcel(py: Python, m: &PyModule) -> PyResult<()> {
fn _fastexcel(m: &Bound<'_, PyModule>) -> PyResult<()> {
let py = m.py();
m.add_function(wrap_pyfunction!(read_excel, m)?)?;
m.add_class::<ColumnInfo>()?;
m.add_class::<ExcelSheet>()?;
Expand All @@ -48,32 +50,38 @@ fn _fastexcel(py: Python, m: &PyModule) -> PyResult<()> {

// errors
[
("FastExcelError", py.get_type::<py_errors::FastExcelError>()),
(
"FastExcelError",
py.get_type_bound::<py_errors::FastExcelError>(),
),
(
"UnsupportedColumnTypeCombinationError",
py.get_type::<py_errors::UnsupportedColumnTypeCombinationError>(),
py.get_type_bound::<py_errors::UnsupportedColumnTypeCombinationError>(),
),
(
"CannotRetrieveCellDataError",
py.get_type::<py_errors::CannotRetrieveCellDataError>(),
py.get_type_bound::<py_errors::CannotRetrieveCellDataError>(),
),
(
"CalamineCellError",
py.get_type::<py_errors::CalamineCellError>(),
py.get_type_bound::<py_errors::CalamineCellError>(),
),
(
"CalamineError",
py.get_type_bound::<py_errors::CalamineError>(),
),
("CalamineError", py.get_type::<py_errors::CalamineError>()),
(
"SheetNotFoundError",
py.get_type::<py_errors::SheetNotFoundError>(),
py.get_type_bound::<py_errors::SheetNotFoundError>(),
),
(
"ColumnNotFoundError",
py.get_type::<py_errors::ColumnNotFoundError>(),
py.get_type_bound::<py_errors::ColumnNotFoundError>(),
),
("ArrowError", py.get_type::<py_errors::ArrowError>()),
("ArrowError", py.get_type_bound::<py_errors::ArrowError>()),
(
"InvalidParametersError",
py.get_type::<py_errors::InvalidParametersError>(),
py.get_type_bound::<py_errors::InvalidParametersError>(),
),
]
.into_iter()
Expand Down
11 changes: 7 additions & 4 deletions src/types/dtype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ use std::{

use arrow::datatypes::{DataType as ArrowDataType, TimeUnit};
use calamine::{CellErrorType, CellType, DataType, Range};
use pyo3::{FromPyObject, PyAny, PyObject, PyResult, Python, ToPyObject};
use pyo3::{
prelude::PyAnyMethods, types::PyString, Bound, FromPyObject, PyAny, PyObject, PyResult, Python,
ToPyObject,
};

use crate::error::{py_errors::IntoPyResult, FastExcelError, FastExcelErrorKind, FastExcelResult};

Expand Down Expand Up @@ -68,9 +71,9 @@ impl ToPyObject for DType {
}

impl FromPyObject<'_> for DType {
fn extract(py_dtype: &PyAny) -> PyResult<Self> {
if let Ok(dtype_str) = py_dtype.extract::<&str>() {
dtype_str.parse()
fn extract_bound(py_dtype: &Bound<'_, PyAny>) -> PyResult<Self> {
if let Ok(dtype_pystr) = py_dtype.extract::<&PyString>() {
dtype_pystr.to_str()?.parse()
} else {
Err(FastExcelErrorKind::InvalidParameters(format!(
"{py_dtype:?} cannot be converted to str"
Expand Down
12 changes: 7 additions & 5 deletions src/types/idx_or_name.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use pyo3::{FromPyObject, PyAny, PyObject, PyResult, Python, ToPyObject};
use pyo3::{
prelude::PyAnyMethods, Bound, FromPyObject, PyAny, PyObject, PyResult, Python, ToPyObject,
};

use crate::error::{py_errors::IntoPyResult, FastExcelError, FastExcelErrorKind, FastExcelResult};

Expand All @@ -17,10 +19,10 @@ impl IdxOrName {
}
}

impl TryFrom<&PyAny> for IdxOrName {
impl TryFrom<&Bound<'_, PyAny>> for IdxOrName {
type Error = FastExcelError;

fn try_from(value: &PyAny) -> FastExcelResult<Self> {
fn try_from(value: &Bound<'_, PyAny>) -> FastExcelResult<Self> {
if let Ok(index) = value.extract() {
Ok(Self::Idx(index))
} else if let Ok(name) = value.extract() {
Expand All @@ -35,8 +37,8 @@ impl TryFrom<&PyAny> for IdxOrName {
}

impl FromPyObject<'_> for IdxOrName {
fn extract(value: &PyAny) -> PyResult<Self> {
value.try_into().into_pyresult()
fn extract_bound(ob: &Bound<'_, PyAny>) -> PyResult<Self> {
ob.try_into().into_pyresult()
}
}

Expand Down
Loading

0 comments on commit b93636e

Please sign in to comment.