Skip to content
Closed
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
7 changes: 7 additions & 0 deletions docs/source/cpp/compute.rst
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,8 @@ Structural transforms
+--------------------------+------------+------------------------------------------------+---------------------+---------+
| list_value_length | Unary | List-like | Int32 or Int64 | \(5) |
+--------------------------+------------+------------------------------------------------+---------------------+---------+
| project | Varargs | Any | Struct | \(6) |
+--------------------------+------------+------------------------------------------------+---------------------+---------+

* \(1) First input must be an array, second input a scalar of the same type.
Output is an array of the same type as the inputs, and with the same values
Expand All @@ -475,6 +477,11 @@ Structural transforms
* \(5) Each output element is the length of the corresponding input element
(null if input is null). Output type is Int32 for List, Int64 for LargeList.

* \(6) The output struct's field types are the types of its arguments. The
field names are specified using an instance of :struct:`ProjectOptions`.
The output shape will be scalar if all inputs are scalar, otherwise any
scalars will be broadcast to arrays.

Conversions
~~~~~~~~~~~

Expand Down
20 changes: 20 additions & 0 deletions python/pyarrow/_compute.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,26 @@ class PartitionNthOptions(_PartitionNthOptions):
self._set_options(pivot)


cdef class _ProjectOptions(FunctionOptions):
cdef:
unique_ptr[CProjectOptions] project_options

cdef const CFunctionOptions* get_options(self) except NULL:
return self.project_options.get()

def _set_options(self, field_names):
cdef:
vector[c_string] c_field_names
for n in field_names:
c_field_names.push_back(tobytes(n))
self.project_options.reset(new CProjectOptions(field_names))


class ProjectOptions(_ProjectOptions):
def __init__(self, field_names):
self._set_options(field_names)


cdef class _MinMaxOptions(FunctionOptions):
cdef:
CMinMaxOptions min_max_options
Expand Down
1 change: 1 addition & 0 deletions python/pyarrow/compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
MinMaxOptions,
ModeOptions,
PartitionNthOptions,
ProjectOptions,
SetLookupOptions,
StrptimeOptions,
TakeOptions,
Expand Down
5 changes: 5 additions & 0 deletions python/pyarrow/includes/libarrow.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -1813,6 +1813,11 @@ cdef extern from "arrow/compute/api.h" namespace "arrow::compute" nogil:
CPartitionNthOptions(int64_t pivot)
int64_t pivot

cdef cppclass CProjectOptions \
"arrow::compute::ProjectOptions"(CFunctionOptions):
CProjectOptions(vector[c_string] field_names)
vector[c_string] field_names

ctypedef enum CSortOrder" arrow::compute::SortOrder":
CSortOrder_Ascending \
"arrow::compute::SortOrder::Ascending"
Expand Down