Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions tools/pythonpkg/src/common/exceptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,9 @@ void RegisterExceptions(const py::module &m) {
} catch (const duckdb::Exception &ex) {
duckdb::ErrorData error(ex);
PyThrowException(error, HTTP_EXCEPTION.ptr());
} catch (const py::builtin_exception &ex) {
// These represent Python exceptions, we don't want to catch these
throw;
} catch (const std::exception &ex) {
duckdb::ErrorData error(ex);
if (error.Type() == ExceptionType::INVALID) {
Expand Down
8 changes: 6 additions & 2 deletions tools/pythonpkg/src/python_udf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,12 @@ static scalar_function_t CreateVectorizedFunction(PyObject *function, PythonExce

single_array[0] = python_object;
single_name[0] = "c0";
python_object = py::module_::import("pyarrow").attr("lib").attr("Table").attr("from_arrays")(
single_array, py::arg("names") = single_name);
try {
python_object = py::module_::import("pyarrow").attr("lib").attr("Table").attr("from_arrays")(
single_array, py::arg("names") = single_name);
} catch (py::error_already_set &ex) {
throw InvalidInputException("Could not convert the result into an Arrow Table");
}
}
// Convert the pyarrow result back to a DuckDB datachunk
ConvertPyArrowToDataChunk(python_object, result, state.GetContext(), count);
Expand Down
4 changes: 2 additions & 2 deletions tools/pythonpkg/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ def pandas_2_or_higher():

def pandas_supports_arrow_backend():
try:
from pandas.compat import pa_version_under7p0
from pandas.compat import pa_version_under11p0

if pa_version_under7p0 == True:
if pa_version_under11p0 == True:
return False
except ImportError:
return False
Expand Down
12 changes: 8 additions & 4 deletions tools/pythonpkg/tests/fast/arrow/test_filter_pushdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,10 @@ def test_struct_filter_pushdown(self, duckdb_cursor, create_table):
"""
).fetchall()

match = re.search(".*ARROW_SCAN.*Filters: s\\.a<2 AND s\\.a IS.*NOT NULL.*", query_res[0][1], flags=re.DOTALL)
input = query_res[0][1]
if 'PANDAS_SCAN' in input:
pytest.skip(reason="This version of pandas does not produce an Arrow object")
match = re.search(".*ARROW_SCAN.*Filters: s\\.a<2 AND s\\.a IS.*NOT NULL.*", input, flags=re.DOTALL)
assert match

# Check that the filter is applied correctly
Expand Down Expand Up @@ -812,9 +815,10 @@ def test_nested_struct_filter_pushdown(self, duckdb_cursor, create_table):
"""
).fetchall()

match = re.search(
".*ARROW_SCAN.*Filters: s\\.a\\.b<2 AND s\\.a\\.b.*IS NOT NULL.*", query_res[0][1], flags=re.DOTALL
)
input = query_res[0][1]
if 'PANDAS_SCAN' in input:
pytest.skip(reason="This version of pandas does not produce an Arrow object")
match = re.search(".*ARROW_SCAN.*Filters: s\\.a\\.b<2 AND s\\.a\\.b.*IS NOT NULL.*", input, flags=re.DOTALL)
assert match

# Check that the filter is applied correctly
Expand Down
2 changes: 1 addition & 1 deletion tools/pythonpkg/tests/fast/udf/test_scalar_arrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def returns_none(col):

con = duckdb.connect()
con.create_function('will_crash', returns_none, [BIGINT], BIGINT, type='arrow')
with pytest.raises(duckdb.Error, match="""TypeError: 'NoneType' object is not iterable"""):
with pytest.raises(duckdb.Error, match="""Could not convert the result into an Arrow Table"""):
res = con.sql("""select will_crash(5)""").fetchall()

def test_empty_result(self):
Expand Down