Skip to content

Commit

Permalink
Cython array box scaffold builds
Browse files Browse the repository at this point in the history
  • Loading branch information
wesm committed Mar 7, 2016
1 parent 94f122f commit 102ed36
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 12 deletions.
1 change: 1 addition & 0 deletions python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@ set(USE_RELATIVE_RPATH ON)
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)

set(CYTHON_EXTENSIONS
array
config
error
parquet
Expand Down
10 changes: 6 additions & 4 deletions python/arrow/array.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@ from arrow.includes.arrow cimport CArray, LogicalType
cdef class Array:
cdef:
shared_ptr[CArray] sp_array
CArray* array

def __len__(self):
return self.array.length()
cdef init(self, const shared_ptr[CArray]& sp_array)


cdef class BooleanArray(Array):
Expand Down Expand Up @@ -67,5 +65,9 @@ cdef class UInt64Array(NumericArray):
pass


cdef class StringArray(NumericArray):
cdef class ListArray(Array):
pass


cdef class StringArray(Array):
pass
84 changes: 81 additions & 3 deletions python/arrow/array.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,90 @@
# distutils: language = c++
# cython: embedsignature = True

from arrow.compat import frombytes, tobytes
from arrow.includes.arrow cimport *
cimport arrow.includes.pyarrow as pyarrow

from arrow.compat import frombytes, tobytes
from arrow.error cimport check_status

cdef class Array:

cdef init(self, const shared_ptr[CArray]& sp_array):
self.sp_array = sp_array

def __len__(self):
return self.array.length()


cdef class BooleanArray(Array):
pass


cdef class NumericArray(Array):
pass


cdef class Int8Array(NumericArray):
pass


cdef class UInt8Array(NumericArray):
pass


cdef class Int16Array(NumericArray):
pass


cdef class UInt16Array(NumericArray):
pass


def from_list(list_obj, type=None):
cdef class Int32Array(NumericArray):
pass


cdef class UInt32Array(NumericArray):
pass


cdef class Int64Array(NumericArray):
pass


cdef class UInt64Array(NumericArray):
pass


cdef class ListArray(Array):
pass


cdef class StringArray(Array):
pass


cdef dict _array_classes = {
LogicalType_BOOL: BooleanArray,
LogicalType_INT64: Int64Array,
LogicalType_LIST: ListArray,
LogicalType_STRING: StringArray,
}

cdef object box_arrow_array(const shared_ptr[CArray]& sp_array):
cdef LogicalType type = sp_array.get().type().get().type

cdef Array arr = _array_classes[type]()
arr.init(sp_array)
return arr


def from_list(object list_obj, type=None):
"""
Convert Python list to Arrow array
"""
pass
cdef:
shared_ptr[CArray] sp_array

check_status(pyarrow.ConvertPySequence(list_obj, &sp_array))
return box_arrow_array(sp_array)
3 changes: 3 additions & 0 deletions python/arrow/includes/arrow.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ cdef extern from "arrow/api.h" namespace "arrow" nogil:

LogicalType_STRING" arrow::LogicalType::STRING"

LogicalType_LIST" arrow::LogicalType::LIST"
LogicalType_STRUCT" arrow::LogicalType::STRUCT"

cdef cppclass CDataType" arrow::DataType":
LogicalType type
c_bool nullable
Expand Down
7 changes: 3 additions & 4 deletions python/arrow/includes/pyarrow.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# distutils: language = c++

from arrow.includes.common cimport *
from arrow.includes.arrow cimport LogicalType, CDataType
from arrow.includes.arrow cimport CArray, CDataType, LogicalType

cdef extern from "pyarrow/api.h" namespace "pyarrow" nogil:
# We can later add more of the common status factory methods as needed
Expand All @@ -38,6 +38,5 @@ cdef extern from "pyarrow/api.h" namespace "pyarrow" nogil:
c_bool IsNotImplemented()
c_bool IsArrowError()


cdef extern from "pyarrow/helpers.h" namespace "pyarrow" nogil:
shared_ptr[CDataType] GetPrimitiveType(LogicalType type, c_bool nullable);
shared_ptr[CDataType] GetPrimitiveType(LogicalType type, c_bool nullable)
Status ConvertPySequence(object obj, shared_ptr[CArray]* out)
2 changes: 1 addition & 1 deletion python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ def get_ext_built(self, name):
return name + suffix

def get_cmake_cython_names(self):
return ['config', 'error', 'parquet', 'schema']
return ['array', 'config', 'error', 'parquet', 'schema']

def get_names(self):
return self._found_names
Expand Down
5 changes: 5 additions & 0 deletions python/src/pyarrow/api.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,9 @@

#include "pyarrow/status.h"

#include "pyarrow/helpers.h"

#include "pyarrow/adapters/builtin.h"
#include "pyarrow/adapters/pandas.h"

#endif // PYARROW_API_H
1 change: 1 addition & 0 deletions python/src/pyarrow/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ namespace pyarrow {

#define PYARROW_IS_PY2 PY_MAJOR_VERSION < 2

// TODO(wesm): We can just let errors pass through. To be explored later
#define RETURN_IF_PYERROR() \
if (PyErr_Occurred()) { \
PyObject *exc_type, *exc_value, *traceback; \
Expand Down

0 comments on commit 102ed36

Please sign in to comment.