Skip to content

Commit 9d29464

Browse files
committed
Change return types to PyDataFusionError to simplify code
1 parent d904d08 commit 9d29464

File tree

15 files changed

+288
-429
lines changed

15 files changed

+288
-429
lines changed

src/catalog.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use std::sync::Arc;
2121
use pyo3::exceptions::PyKeyError;
2222
use pyo3::prelude::*;
2323

24-
use crate::errors::PyDataFusionError;
24+
use crate::errors::{PyDataFusionError, PyDataFusionResult};
2525
use crate::utils::wait_for_future;
2626
use datafusion::{
2727
arrow::pyarrow::ToPyArrow,
@@ -96,13 +96,13 @@ impl PyDatabase {
9696
self.database.table_names().into_iter().collect()
9797
}
9898

99-
fn table(&self, name: &str, py: Python) -> PyResult<PyTable> {
100-
if let Some(table) =
101-
wait_for_future(py, self.database.table(name)).map_err(PyDataFusionError::from)?
102-
{
99+
fn table(&self, name: &str, py: Python) -> PyDataFusionResult<PyTable> {
100+
if let Some(table) = wait_for_future(py, self.database.table(name))? {
103101
Ok(PyTable::new(table))
104102
} else {
105-
Err(PyDataFusionError::Common(format!("Table not found: {name}")).into())
103+
Err(PyDataFusionError::Common(format!(
104+
"Table not found: {name}"
105+
)))
106106
}
107107
}
108108

src/config.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use pyo3::types::*;
2121
use datafusion::common::ScalarValue;
2222
use datafusion::config::ConfigOptions;
2323

24-
use crate::errors::PyDataFusionError;
24+
use crate::errors::PyDataFusionResult;
2525

2626
#[pyclass(name = "Config", module = "datafusion", subclass)]
2727
#[derive(Clone)]
@@ -40,9 +40,9 @@ impl PyConfig {
4040

4141
/// Get configurations from environment variables
4242
#[staticmethod]
43-
pub fn from_env() -> PyResult<Self> {
43+
pub fn from_env() -> PyDataFusionResult<Self> {
4444
Ok(Self {
45-
config: ConfigOptions::from_env().map_err(PyDataFusionError::from)?,
45+
config: ConfigOptions::from_env()?,
4646
})
4747
}
4848

@@ -58,12 +58,10 @@ impl PyConfig {
5858
}
5959

6060
/// Set a configuration option
61-
pub fn set(&mut self, key: &str, value: PyObject, py: Python) -> PyResult<()> {
61+
pub fn set(&mut self, key: &str, value: PyObject, py: Python) -> PyDataFusionResult<()> {
6262
let scalar_value = py_obj_to_scalar_value(py, value);
63-
self.config
64-
.set(key, scalar_value.to_string().as_str())
65-
.map_err(PyDataFusionError::from)
66-
.map_err(PyErr::from)
63+
self.config.set(key, scalar_value.to_string().as_str())?;
64+
Ok(())
6765
}
6866

6967
/// Get all configuration options

0 commit comments

Comments
 (0)