Skip to content

Commit

Permalink
feat: better exception and message for table not found
Browse files Browse the repository at this point in the history
closes apache#796
  • Loading branch information
mesejo committed Sep 2, 2024
1 parent 003eea8 commit 601eed6
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 601eed6

Please sign in to comment.