-
Notifications
You must be signed in to change notification settings - Fork 208
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Installing pyarrow in ci workflow Split Table, RecordBatch and Field/Schema bindings into separate headers
- Loading branch information
1 parent
22c5eba
commit d32a07a
Showing
8 changed files
with
145 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
.. _pyarrow: | ||
|
||
PyArrow Bindings | ||
================ | ||
|
||
nanobind can exchange ``pyarrow`` objects via a ``std::shared_ptr<..>``. To get started you have to | ||
|
||
.. code-block:: cpp | ||
#include <nanobind/pyarrow/pyarrow_import.h> | ||
and make sure to call the following `pyarrow initialization <https://arrow.apache.org/docs/python/integration/extending.html#_CPPv4N5arrow14import_pyarrowEv>`__ on top of your module definition | ||
|
||
.. code-block:: cpp | ||
NB_MODULE(test_pyarrow_ext, m) { | ||
static nanobind::detail::pyarrow::ImportPyarrow module; | ||
// ... | ||
} | ||
The type caster headers are structured in a similar form than the headers in ``pyarrow`` (``array_primitive.h``, ``array_binary.h``, etc) itself: | ||
|
||
.. list-table:: | ||
:widths: 42 48 | ||
:header-rows: 1 | ||
|
||
* - Types | ||
- Type caster header | ||
* - ``Array``, ``DoubleArray``, ``Int64Array``, ... | ||
- ``#include <nanobind/pyarrow/array_primitive.h>`` | ||
* - ``BinaryArray``, ``LargeBinaryArray``, ``StringArray``, ``LargeStringArray``, ``FixedSizeBinaryArray`` | ||
- ``#include <nanobind/pyarrow/array_binary.h>`` | ||
* - ``ListArray``, ``LargeListArray``, ``MapArray``, ``FixedSizeListArray``, ``StructArray``, ``UnionArray``, ``SparseUnionArray``, ``DenseUnionArray`` | ||
- ``#include <nanobind/pyarrow/array_nested.h>`` | ||
* - ``ChunkedArray`` | ||
- ``#include <nanobind/pyarrow/chunked_array.h>`` | ||
* - ``Table`` | ||
- ``#include <nanobind/pyarrow/table.h>`` | ||
* - ``RecordBatch`` | ||
- ``#include <nanobind/pyarrow/record_batch.h>`` | ||
* - ``Field``, ``Schema`` | ||
- ``#include <nanobind/pyarrow/type.h>`` | ||
* - ``Scalars`` | ||
- ``#include <nanobind/pyarrow/scalar.h>`` | ||
* - ``DataTypes`` | ||
- ``#include <nanobind/pyarrow/datatype.h>`` | ||
* - ``Buffer``, ``ResizableBuffer``, ``MutableBuffer`` | ||
- ``#include <nanobind/pyarrow/buffer.h>`` | ||
* - ``Tensor``, ``NumericTensor<..>`` | ||
- ``#include <nanobind/pyarrow/tensor.h>`` | ||
* - ``SparseCOOTensor``, ``SparseCSCMatrix``, ``SparseCSFTensor``, ``SparseCSRMatrix`` | ||
- ``#include <nanobind/pyarrow/sparse_tensor.h>`` | ||
|
||
**Example**: The following code snippet shows how to create bindings for a ``pyarrow.DoubleArray``: | ||
|
||
.. code-block:: cpp | ||
#include <memory> | ||
#include <nanobind/nanobind.h> | ||
#include <nanobind/pyarrow/pyarrow_import.h> | ||
#include <nanobind/pyarrow/array_primitive.h> | ||
namespace nb = nanobind; | ||
NB_MODULE(test_pyarrow_ext, m) { | ||
static nb::detail::pyarrow::ImportPyarrow module; | ||
m.def("my_pyarrow_function", [](std::shared_ptr<arrow::DoubleArray> arr) { | ||
auto data = arr->data()->Copy(); | ||
return std::make_shared<arrow::DoubleArray>(std::move(data)); | ||
} | ||
); | ||
} | ||
If you want to consume the ``C++`` artifacts as distributed by the ``PyPi`` ``pyarrow`` package in your own ``CMake`` | ||
project, please have a look at `FindPyArrow.cmake <https://github.com/wjakob/nanobind/cmake/FindPyArrow.cmake>`__. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
nanobind/pyarrow/record_batch.h: conversion between arrow and pyarrow | ||
Copyright (c) 2024 Maximilian Kleinert <[email protected]> and | ||
Wenzel Jakob <[email protected]> | ||
All rights reserved. Use of this source code is governed by a | ||
BSD-style license that can be found in the LICENSE file. | ||
*/ | ||
#pragma once | ||
|
||
#include <nanobind/nanobind.h> | ||
#include <memory> | ||
#include <nanobind/pyarrow/detail/caster.h> | ||
#include <arrow/record_batch.h> | ||
|
||
NAMESPACE_BEGIN(NB_NAMESPACE) | ||
NAMESPACE_BEGIN(detail) | ||
|
||
template<> | ||
struct pyarrow::pyarrow_caster_name_trait<arrow::RecordBatch> { | ||
static constexpr auto Name = const_name("RecordBatch"); | ||
}; | ||
template<> | ||
struct type_caster<std::shared_ptr<arrow::RecordBatch>> : pyarrow::pyarrow_caster<arrow::RecordBatch, arrow::py::is_batch, arrow::py::wrap_batch, arrow::py::unwrap_batch> {}; | ||
|
||
NAMESPACE_END(detail) | ||
NAMESPACE_END(NB_NAMESPACE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
nanobind/pyarrow/table.h: conversion between arrow and pyarrow | ||
Copyright (c) 2024 Maximilian Kleinert <[email protected]> and | ||
Wenzel Jakob <[email protected]> | ||
All rights reserved. Use of this source code is governed by a | ||
BSD-style license that can be found in the LICENSE file. | ||
*/ | ||
#pragma once | ||
|
||
#include <nanobind/nanobind.h> | ||
#include <memory> | ||
#include <nanobind/pyarrow/detail/caster.h> | ||
#include <arrow/table.h> | ||
|
||
NAMESPACE_BEGIN(NB_NAMESPACE) | ||
NAMESPACE_BEGIN(detail) | ||
|
||
template<> | ||
struct pyarrow::pyarrow_caster_name_trait<arrow::Table> { | ||
static constexpr auto Name = const_name("Table"); | ||
}; | ||
template<> | ||
struct type_caster<std::shared_ptr<arrow::Table>> : pyarrow::pyarrow_caster<arrow::Table, arrow::py::is_table, arrow::py::wrap_table, arrow::py::unwrap_table> {}; | ||
|
||
NAMESPACE_END(detail) | ||
NAMESPACE_END(NB_NAMESPACE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
nanobind/pyarrow/tabular.h: conversion between arrow and pyarrow | ||
nanobind/pyarrow/type.h: conversion between arrow and pyarrow | ||
Copyright (c) 2024 Maximilian Kleinert <[email protected]> and | ||
Wenzel Jakob <[email protected]> | ||
|
@@ -12,28 +12,11 @@ | |
#include <nanobind/nanobind.h> | ||
#include <memory> | ||
#include <nanobind/pyarrow/detail/caster.h> | ||
#include <arrow/record_batch.h> | ||
#include <arrow/table.h> | ||
#include <arrow/type.h> | ||
|
||
NAMESPACE_BEGIN(NB_NAMESPACE) | ||
NAMESPACE_BEGIN(detail) | ||
|
||
template<> | ||
struct pyarrow::pyarrow_caster_name_trait<arrow::Table> { | ||
static constexpr auto Name = const_name("Table"); | ||
}; | ||
template<> | ||
struct type_caster<std::shared_ptr<arrow::Table>> : pyarrow::pyarrow_caster<arrow::Table, arrow::py::is_table, arrow::py::wrap_table, arrow::py::unwrap_table> {}; | ||
|
||
template<> | ||
struct pyarrow::pyarrow_caster_name_trait<arrow::RecordBatch> { | ||
static constexpr auto Name = const_name("RecordBatch"); | ||
}; | ||
template<> | ||
struct type_caster<std::shared_ptr<arrow::RecordBatch>> : pyarrow::pyarrow_caster<arrow::RecordBatch, arrow::py::is_batch, arrow::py::wrap_batch, arrow::py::unwrap_batch> {}; | ||
|
||
|
||
template<> | ||
struct pyarrow::pyarrow_caster_name_trait<arrow::Schema> { | ||
static constexpr auto Name = const_name("Schema"); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters