Skip to content

Commit fe0738a

Browse files
authored
feat: better exception and message for table not found (#851)
closes #796
1 parent 909b809 commit fe0738a

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

python/datafusion/tests/test_context.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,13 @@ def test_table_exist(ctx):
466466
assert ctx.table_exist("t") is True
467467

468468

469+
def test_table_not_found(ctx):
470+
from uuid import uuid4
471+
472+
with pytest.raises(KeyError):
473+
ctx.table(f"not-found-{uuid4()}")
474+
475+
469476
def test_read_json(ctx):
470477
path = os.path.dirname(os.path.abspath(__file__))
471478

src/context.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -765,7 +765,8 @@ impl PySessionContext {
765765
}
766766

767767
pub fn table(&self, name: &str, py: Python) -> PyResult<PyDataFrame> {
768-
let x = wait_for_future(py, self.ctx.table(name)).map_err(DataFusionError::from)?;
768+
let x = wait_for_future(py, self.ctx.table(name))
769+
.map_err(|e| PyKeyError::new_err(e.to_string()))?;
769770
Ok(PyDataFrame::new(x))
770771
}
771772

0 commit comments

Comments
 (0)