Skip to content

Commit

Permalink
feat: better exception and message for table not found (#851)
Browse files Browse the repository at this point in the history
closes #796
  • Loading branch information
mesejo authored and allinux committed Sep 7, 2024
1 parent 909b809 commit 6409af3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
7 changes: 7 additions & 0 deletions python/datafusion/tests/test_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,13 @@ def test_table_exist(ctx):
assert ctx.table_exist("t") is True


def test_table_not_found(ctx):
from uuid import uuid4

with pytest.raises(KeyError):
ctx.table(f"not-found-{uuid4()}")


def test_read_json(ctx):
path = os.path.dirname(os.path.abspath(__file__))

Expand Down
3 changes: 2 additions & 1 deletion src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,8 @@ impl PySessionContext {
}

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

Expand Down

0 comments on commit 6409af3

Please sign in to comment.