Skip to content

Commit

Permalink
build(deps): bump arrow to 53.1.0 and pyo3 to 0.22.3 (#298)
Browse files Browse the repository at this point in the history
  • Loading branch information
PrettyWood authored Oct 14, 2024
1 parent 4e55199 commit 102278d
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 190 deletions.
213 changes: 55 additions & 158 deletions Cargo.lock

Large diffs are not rendered by default.

9 changes: 2 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,11 @@ name = "fastexcel"
crate-type = ["cdylib"]

[dependencies]
arrow = { version = "53.1.0", default-features = false, features = ["pyarrow"] }
calamine = { version = "0.26.1", features = ["dates"] }
chrono = { version = "0.4.38", default-features = false }
# NOTE: "extension-module" is actually required, see comments on features below
pyo3 = { version = "0.21.2", features = ["abi3-py38"] }

[dependencies.arrow]
version = "52.2.0"
# There's a lot of stuff we don't want here, such as serde support
default-features = false
features = ["pyarrow"]
pyo3 = { version = "0.22.3", features = ["abi3-py38", "experimental-inspect"] }

[dev-dependencies]
pretty_assertions = "1.4.1"
Expand Down
6 changes: 3 additions & 3 deletions python/fastexcel/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,15 +263,15 @@ def load_sheet(
)
)

def table_names(self, sheet_idx_or_name: str | int | None = None) -> list[str]:
def table_names(self, sheet_name: str | None = None) -> list[str]:
"""The list of table names.
Will return an empty list if no tables are found.
:param sheet_idx_or_name: If given, will limit the list to the given sheet, will be faster
:param sheet_name: If given, will limit the list to the given sheet, will be faster
too.
"""
return self._reader.table_names(sheet_idx_or_name)
return self._reader.table_names(sheet_name)

@typing.overload
def load_table(
Expand Down
2 changes: 1 addition & 1 deletion python/fastexcel/_fastexcel.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ class _ExcelReader:
) -> pa.RecordBatch: ...
@property
def sheet_names(self) -> list[str]: ...
def table_names(self, sheet_idx_or_name: str | int | None = None) -> list[str]: ...
def table_names(self, sheet_name: str | None = None) -> list[str]: ...

def read_excel(source: str | bytes) -> _ExcelReader:
"""Reads an excel file and returns an ExcelReader"""
Expand Down
7 changes: 3 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ mod types;
mod utils;

use error::{py_errors, ErrorContext};
use pyo3::{prelude::*, types::PyString};
use pyo3::prelude::*;
use types::python::{
excelsheet::column_info::ColumnInfo, table::ExcelTable, ExcelReader, ExcelSheet,
};
Expand All @@ -14,9 +14,8 @@ use types::python::{
fn read_excel(source: &Bound<'_, PyAny>) -> PyResult<ExcelReader> {
use py_errors::IntoPyResult;

if let Ok(path) = source.extract::<&PyString>() {
let path = path.to_str()?;
ExcelReader::try_from_path(path)
if let Ok(path) = source.extract::<String>() {
ExcelReader::try_from_path(&path)
.with_context(|| format!("could not load excel file at {path}"))
.into_pyresult()
} else if let Ok(bytes) = source.extract::<&[u8]>() {
Expand Down
11 changes: 5 additions & 6 deletions src/types/dtype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ use std::{
use arrow::datatypes::{DataType as ArrowDataType, TimeUnit};
use calamine::{CellErrorType, CellType, DataType, Range};
use pyo3::{
prelude::PyAnyMethods, types::PyString, Bound, FromPyObject, PyAny, PyObject, PyResult, Python,
ToPyObject,
prelude::PyAnyMethods, Bound, FromPyObject, PyAny, PyObject, PyResult, Python, ToPyObject,
};

use crate::error::{py_errors::IntoPyResult, FastExcelError, FastExcelErrorKind, FastExcelResult};
Expand Down Expand Up @@ -72,8 +71,8 @@ impl ToPyObject for DType {

impl FromPyObject<'_> for DType {
fn extract_bound(py_dtype: &Bound<'_, PyAny>) -> PyResult<Self> {
if let Ok(dtype_pystr) = py_dtype.extract::<&PyString>() {
dtype_pystr.to_str()?.parse()
if let Ok(dtype_pystr) = py_dtype.extract::<String>() {
dtype_pystr.parse()
} else {
Err(FastExcelErrorKind::InvalidParameters(format!(
"{py_dtype:?} cannot be converted to str"
Expand Down Expand Up @@ -124,8 +123,8 @@ impl FromStr for DTypeCoercion {

impl FromPyObject<'_> for DTypeCoercion {
fn extract_bound(py_dtype_coercion: &Bound<'_, PyAny>) -> PyResult<Self> {
if let Ok(dtype_coercion_pystr) = py_dtype_coercion.extract::<&PyString>() {
dtype_coercion_pystr.to_str()?.parse()
if let Ok(dtype_coercion_pystr) = py_dtype_coercion.extract::<String>() {
dtype_coercion_pystr.parse()
} else {
Err(FastExcelErrorKind::InvalidParameters(format!(
"{py_dtype_coercion:?} cannot be converted to str"
Expand Down
1 change: 1 addition & 0 deletions src/types/python/excelreader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ impl ExcelReader {
format!("ExcelReader<{}>", &self.source)
}

#[pyo3(signature = (sheet_name = None))]
pub fn table_names(&mut self, sheet_name: Option<&str>) -> PyResult<Vec<String>> {
self.sheets.table_names(sheet_name).into_pyresult()
}
Expand Down
15 changes: 4 additions & 11 deletions src/types/python/excelsheet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use arrow::{pyarrow::ToPyArrow, record_batch::RecordBatch};

use pyo3::{
prelude::{pyclass, pymethods, PyAnyMethods, Python},
types::{PyList, PyString},
types::PyList,
Bound, PyAny, PyObject, PyResult, ToPyObject,
};

Expand Down Expand Up @@ -294,15 +294,8 @@ impl TryFrom<Option<&Bound<'_, PyAny>>> for SelectedColumns {
Some(py_any) => {
// Not trying to downcast to PyNone here as we assume that this would result in
// py_any_opt being None
if let Ok(py_str) = py_any.extract::<&PyString>() {
py_str
.to_str()
.map_err(|err| {
FastExcelErrorKind::InvalidParameters(format!(
"provided string is not valid unicode: {err}"
))
})?
.parse()
if let Ok(py_str) = py_any.extract::<String>() {
py_str.parse()
} else if let Ok(py_list) = py_any.downcast::<PyList>() {
py_list.try_into()
} else if let Ok(py_function) = py_any.extract::<PyObject>() {
Expand Down Expand Up @@ -530,7 +523,7 @@ impl ExcelSheet {
mod tests {
use super::*;
use pretty_assertions::assert_eq;
use pyo3::prelude::PyListMethods;
use pyo3::{prelude::PyListMethods, types::PyString};
use rstest::rstest;

#[test]
Expand Down

0 comments on commit 102278d

Please sign in to comment.