Introduce NumpyArray façade over py::array#513
Merged
evertlammerts merged 1 commit intoJun 26, 2026
Conversation
Add a thin wrapper class `NumpyArray` (src/duckdb_py/include/duckdb_python/
numpy/numpy_array.hpp) whose single data member is a `py::array`. This is now
the only spot in the codebase that names `py::array` as the underlying
numpy-array representation, so a future migration to nanobind's `nb::ndarray`
is localized to this one header.
The façade exposes Data()/MutableData() (data buffer pointers), an Allocate()
factory (dtype + count), a FromObject() factory, an `explicit
NumpyArray(py::array)` constructor (a py::object argument implicitly converts
via np.asarray semantics, matching prior behaviour), and GetArray() accessors
for .attr(...) calls, iteration, resize, and handing the array back to Python.
It is default-constructible, copyable, and movable.
Route every direct py::array use through the façade:
- numpy/raw_array_wrapper.{hpp,cpp}: member + Allocate/MutableData, resize via
GetArray()
- pandas/pandas_bind.hpp (RegisteredArray) and pandas/column/
pandas_numpy_column.hpp: members + constructors take NumpyArray
- numpy/numpy_scan.cpp: scan helpers take NumpyArray&, .data() -> .Data()
- numpy/numpy_bind.cpp, pandas/bind.cpp: construct NumpyArray instead of
py::array; dtype attrs via GetArray()
- numpy/array_wrapper.cpp (ToArray): move out / bool-check via GetArray()
- pyconnection.cpp, python_replacement_scan.cpp: py::cast<py::array>(...) ->
wrap the object in NumpyArray and use GetArray()
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add a thin wrapper class
NumpyArray(src/duckdb_py/include/duckdb_python/ numpy/numpy_array.hpp) whose single data member is apy::array. This is now the only spot in the codebase that namespy::arrayas the underlying numpy-array representation, so a future migration to nanobind'snb::ndarrayis localized to this one header.The façade exposes Data()/MutableData() (data buffer pointers), an Allocate() factory (dtype + count), a FromObject() factory, an
explicit NumpyArray(py::array)constructor (a py::object argument implicitly converts via np.asarray semantics, matching prior behaviour), and GetArray() accessors for .attr(...) calls, iteration, resize, and handing the array back to Python. It is default-constructible, copyable, and movable.Route every direct py::array use through the façade:
wrap the object in NumpyArray and use GetArray()