@@ -307,26 +307,31 @@ static scalar_function_t CreateNativeFunction(PyObject *function, PythonExceptio
307307
308308 for (idx_t row = 0 ; row < input.size (); row++) {
309309
310- auto bundled_parameters = py::tuple ((int )input.ColumnCount ());
311- bool contains_null = false ;
312- for (idx_t i = 0 ; i < input.ColumnCount (); i++) {
313- // Fill the tuple with the arguments for this row
314- auto &column = input.data [i];
315- auto value = column.GetValue (row);
316- if (value.IsNull () && default_null_handling) {
317- contains_null = true ;
318- break ;
310+ py::object ret;
311+ if (input.ColumnCount () > 0 ) {
312+ auto bundled_parameters = py::tuple ((int )input.ColumnCount ());
313+ bool contains_null = false ;
314+ for (idx_t i = 0 ; i < input.ColumnCount (); i++) {
315+ // Fill the tuple with the arguments for this row
316+ auto &column = input.data [i];
317+ auto value = column.GetValue (row);
318+ if (value.IsNull () && default_null_handling) {
319+ contains_null = true ;
320+ break ;
321+ }
322+ bundled_parameters[i] = PythonObject::FromValue (value, column.GetType (), client_properties);
319323 }
320- bundled_parameters[i] = PythonObject::FromValue (value, column.GetType (), client_properties);
321- }
322- if (contains_null) {
323- // Immediately insert None, no need to call the function
324- FlatVector::SetNull (result, row, true );
325- continue ;
324+ if (contains_null) {
325+ // Immediately insert None, no need to call the function
326+ FlatVector::SetNull (result, row, true );
327+ continue ;
328+ }
329+ // Call the function
330+ ret = py::reinterpret_steal<py::object>(PyObject_CallObject (function, bundled_parameters.ptr ()));
331+ } else {
332+ ret = py::reinterpret_steal<py::object>(PyObject_CallObject (function, nullptr ));
326333 }
327334
328- // Call the function
329- auto ret = py::reinterpret_steal<py::object>(PyObject_CallObject (function, bundled_parameters.ptr ()));
330335 if (ret == nullptr && PyErr_Occurred ()) {
331336 if (exception_handling == PythonExceptionHandling::FORWARD_ERROR ) {
332337 auto exception = py::error_already_set ();
0 commit comments