Skip to content
Open
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
26 changes: 26 additions & 0 deletions cpp/src/arrow/array/util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -927,6 +927,32 @@ Result<std::shared_ptr<Array>> MakeEmptyArray(std::shared_ptr<DataType> type,
return builder->Finish();
}

Result<std::shared_ptr<Array>> Arange(int64_t start, int64_t stop, int64_t step,
MemoryPool* pool) {
if (step == 0) {
return Status::Invalid("arange: step cannot be zero");
}

int64_t size;
if (step > 0 && stop > start) {
size = (stop - start + step - 1) / step;
} else if (step < 0 && stop < start) {
size = (start - stop - step - 1) / (-step);
} else {
return MakeEmptyArray(int64(), pool);
}

ARROW_ASSIGN_OR_RAISE(auto data_buffer, AllocateBuffer(size * sizeof(int64_t), pool));

auto values = reinterpret_cast<int64_t*>(data_buffer->mutable_data());
for (int64_t i = 0; i < size; ++i) {
values[i] = start + i * step;
}

auto data = ArrayData::Make(int64(), size, {nullptr, std::move(data_buffer)}, 0);
return MakeArray(data);
}

namespace internal {

std::vector<ArrayVector> RechunkArraysConsistently(
Expand Down
15 changes: 15 additions & 0 deletions cpp/src/arrow/array/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,21 @@ ARROW_EXPORT
Result<std::shared_ptr<Array>> MakeEmptyArray(std::shared_ptr<DataType> type,
MemoryPool* pool = default_memory_pool());

/// \brief Create an array of evenly spaced integer values
///
/// Generates a sequence of integers from start (inclusive) to stop (exclusive)
/// with the given step, similar to Python's range() or NumPy's arange().
/// The resulting array will have type Int64.
///
/// \param[in] start First value in the sequence
/// \param[in] stop End value (exclusive)
/// \param[in] step Spacing between values (must not be zero)
/// \param[in] pool the memory pool to allocate memory from
/// \return the resulting Int64Array
ARROW_EXPORT
Result<std::shared_ptr<Array>> Arange(int64_t start, int64_t stop, int64_t step,
MemoryPool* pool = default_memory_pool());

/// @}

namespace internal {
Expand Down
3 changes: 1 addition & 2 deletions python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -375,8 +375,7 @@ set(PYARROW_CPP_SRCS
${PYARROW_CPP_SOURCE_DIR}/python_test.cc
${PYARROW_CPP_SOURCE_DIR}/python_to_arrow.cc
${PYARROW_CPP_SOURCE_DIR}/pyarrow.cc
${PYARROW_CPP_SOURCE_DIR}/udf.cc
${PYARROW_CPP_SOURCE_DIR}/util.cc)
${PYARROW_CPP_SOURCE_DIR}/udf.cc)
set_source_files_properties(${PYARROW_CPP_SOURCE_DIR}/numpy_init.cc
PROPERTIES SKIP_UNITY_BUILD_INCLUSION ON)

Expand Down
3 changes: 3 additions & 0 deletions python/pyarrow/includes/libarrow.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,9 @@ cdef extern from "arrow/api.h" namespace "arrow" nogil:
CResult[shared_ptr[CArray]] MakeArrayFromScalar(
const CScalar& scalar, int64_t length, CMemoryPool* pool)

CResult[shared_ptr[CArray]] Arange(int64_t start, int64_t stop,
int64_t step, CMemoryPool* pool)

CStatus DebugPrint(const CArray& arr, int indent)

cdef cppclass CFixedWidthType" arrow::FixedWidthType"(CDataType):
Expand Down
3 changes: 0 additions & 3 deletions python/pyarrow/includes/libarrow_python.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,6 @@ cdef extern from "arrow/python/api.h" namespace "arrow::py" nogil:
object obj, object mask, const PyConversionOptions& options,
CMemoryPool* pool)

CResult[shared_ptr[CArray]] Arange(int64_t start, int64_t stop,
int64_t step, CMemoryPool* pool)

CResult[shared_ptr[CDataType]] NumPyDtypeToArrow(object dtype)

CStatus NdarrayToArrow(CMemoryPool* pool, object ao, object mo,
Expand Down
1 change: 0 additions & 1 deletion python/pyarrow/src/arrow/python/api.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,3 @@
#include "arrow/python/numpy_convert.h"
#include "arrow/python/numpy_to_arrow.h"
#include "arrow/python/python_to_arrow.h"
#include "arrow/python/util.h"
50 changes: 0 additions & 50 deletions python/pyarrow/src/arrow/python/util.cc

This file was deleted.

40 changes: 0 additions & 40 deletions python/pyarrow/src/arrow/python/util.h

This file was deleted.

Loading