This is an automated email from the ASF dual-hosted git repository.
agrove pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/datafusion-python.git
The following commit(s) were added to refs/heads/main by this push:
new fe0738a feat: better exception and message for table not found (#851)
fe0738a is described below
commit fe0738a9c0b536cdf20b0dc0455d14a0d16d2835
Author: Daniel Mesejo <[email protected]>
AuthorDate: Mon Sep 2 17:28:59 2024 +0200
feat: better exception and message for table not found (#851)
closes #796
---
python/datafusion/tests/test_context.py | 7 +++++++
src/context.rs | 3 ++-
2 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/python/datafusion/tests/test_context.py
b/python/datafusion/tests/test_context.py
index 0184280..4af00a3 100644
--- a/python/datafusion/tests/test_context.py
+++ b/python/datafusion/tests/test_context.py
@@ -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__))
diff --git a/src/context.rs b/src/context.rs
index 4433d94..3ab7834 100644
--- a/src/context.rs
+++ b/src/context.rs
@@ -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))
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]