@@ -17,18 +17,28 @@ namespace duckdb {
1717
1818namespace pyarrow {
1919
20- py::object ToArrowTable (const vector<LogicalType> &types, const vector<string> &names, const py::list &batches,
21- ClientProperties &options) {
20+ py::object ToPyArrowSchema (const ArrowSchema &schema) {
2221 py::gil_scoped_acquire acquire;
2322
2423 auto pyarrow_lib_module = py::module::import (" pyarrow" ).attr (" lib" );
25- auto from_batches_func = pyarrow_lib_module.attr (" Table" ).attr (" from_batches" );
2624 auto schema_import_func = pyarrow_lib_module.attr (" Schema" ).attr (" _import_from_c" );
25+ return schema_import_func (reinterpret_cast <uint64_t >(&schema));
26+ }
27+
28+ py::object ToArrowTable (const py::list &batches, py::object pyarrow_schema) {
29+ py::gil_scoped_acquire acquire;
30+
31+ auto pyarrow_lib_module = py::module::import (" pyarrow" ).attr (" lib" );
32+ auto from_batches_func = pyarrow_lib_module.attr (" Table" ).attr (" from_batches" );
33+
34+ return py::cast<duckdb::pyarrow::Table>(from_batches_func (batches, pyarrow_schema));
35+ }
36+
37+ py::object ToArrowTable (const vector<LogicalType> &types, const vector<string> &names, const py::list &batches,
38+ ClientProperties &options) {
2739 ArrowSchema schema;
2840 ArrowConverter::ToArrowSchema (&schema, types, names, options);
29- auto schema_obj = schema_import_func (reinterpret_cast <uint64_t >(&schema));
30-
31- return py::cast<duckdb::pyarrow::Table>(from_batches_func (batches, schema_obj));
41+ return ToArrowTable (batches, ToPyArrowSchema (schema));
3242}
3343
3444} // namespace pyarrow
0 commit comments