Repository: arrow Updated Branches: refs/heads/master 74bc4dd48 -> 5439b7158
http://git-wip-us.apache.org/repos/asf/arrow/blob/5439b715/python/src/pyarrow/adapters/pandas.cc ---------------------------------------------------------------------- diff --git a/python/src/pyarrow/adapters/pandas.cc b/python/src/pyarrow/adapters/pandas.cc index 8d05821..345dc90 100644 --- a/python/src/pyarrow/adapters/pandas.cc +++ b/python/src/pyarrow/adapters/pandas.cc @@ -1338,8 +1338,7 @@ class ArrowSerializer { PyAcquireGIL lock; PyObject** objects = reinterpret_cast<PyObject**>(PyArray_DATA(arr_)); - arrow::TypePtr string_type(new arrow::DateType()); - arrow::DateBuilder date_builder(pool_, string_type); + arrow::DateBuilder date_builder(pool_); RETURN_NOT_OK(date_builder.Resize(length_)); Status s; @@ -1363,8 +1362,7 @@ class ArrowSerializer { // and unicode mixed in the object array PyObject** objects = reinterpret_cast<PyObject**>(PyArray_DATA(arr_)); - arrow::TypePtr string_type(new arrow::StringType()); - arrow::StringBuilder string_builder(pool_, string_type); + arrow::StringBuilder string_builder(pool_); RETURN_NOT_OK(string_builder.Resize(length_)); Status s; @@ -1374,8 +1372,8 @@ class ArrowSerializer { if (have_bytes) { const auto& arr = static_cast<const arrow::StringArray&>(*out->get()); - *out = std::make_shared<arrow::BinaryArray>( - arr.length(), arr.offsets(), arr.data(), arr.null_count(), arr.null_bitmap()); + *out = std::make_shared<arrow::BinaryArray>(arr.length(), arr.value_offsets(), + arr.data(), arr.null_bitmap(), arr.null_count()); } return Status::OK(); } @@ -1403,7 +1401,7 @@ class ArrowSerializer { } } - *out = std::make_shared<arrow::BooleanArray>(length_, data, null_count, null_bitmap_); + *out = std::make_shared<arrow::BooleanArray>(length_, data, null_bitmap_, null_count); return Status::OK(); } @@ -1515,10 +1513,14 @@ inline Status ArrowSerializer<TYPE>::Convert(std::shared_ptr<Array>* out) { null_count = ValuesToBitmap<TYPE>(PyArray_DATA(arr_), length_, null_bitmap_data_); } + // For readability + constexpr int32_t kOffset = 0; + RETURN_NOT_OK(ConvertData()); std::shared_ptr<DataType> type; RETURN_NOT_OK(MakeDataType(&type)); - RETURN_NOT_OK(MakePrimitiveArray(type, length_, data_, null_count, null_bitmap_, out)); + RETURN_NOT_OK( + MakePrimitiveArray(type, length_, data_, null_bitmap_, null_count, kOffset, out)); return Status::OK(); } @@ -1657,7 +1659,7 @@ ArrowSerializer<NPY_OBJECT>::ConvertTypedLists<NPY_OBJECT, ::arrow::StringType>( // TODO: If there are bytes involed, convert to Binary representation bool have_bytes = false; - auto value_builder = std::make_shared<arrow::StringBuilder>(pool_, field->type); + auto value_builder = std::make_shared<arrow::StringBuilder>(pool_); ListBuilder list_builder(pool_, value_builder); PyObject** objects = reinterpret_cast<PyObject**>(PyArray_DATA(arr_)); for (int64_t i = 0; i < length_; ++i) { http://git-wip-us.apache.org/repos/asf/arrow/blob/5439b715/python/src/pyarrow/io.cc ---------------------------------------------------------------------- diff --git a/python/src/pyarrow/io.cc b/python/src/pyarrow/io.cc index 9235260..aa4cb7b 100644 --- a/python/src/pyarrow/io.cc +++ b/python/src/pyarrow/io.cc @@ -56,9 +56,20 @@ static Status CheckPyError() { return Status::OK(); } +// This is annoying: because C++11 does not allow implicit conversion of string +// literals to non-const char*, we need to go through some gymnastics to use +// PyObject_CallMethod without a lot of pain (its arguments are non-const +// char*) +template <typename... ArgTypes> +static inline PyObject* cpp_PyObject_CallMethod( + PyObject* obj, const char* method_name, const char* argspec, ArgTypes... args) { + return PyObject_CallMethod( + obj, const_cast<char*>(method_name), const_cast<char*>(argspec), args...); +} + Status PythonFile::Close() { // whence: 0 for relative to start of file, 2 for end of file - PyObject* result = PyObject_CallMethod(file_, "close", "()"); + PyObject* result = cpp_PyObject_CallMethod(file_, "close", "()"); Py_XDECREF(result); ARROW_RETURN_NOT_OK(CheckPyError()); return Status::OK(); @@ -66,14 +77,14 @@ Status PythonFile::Close() { Status PythonFile::Seek(int64_t position, int whence) { // whence: 0 for relative to start of file, 2 for end of file - PyObject* result = PyObject_CallMethod(file_, "seek", "(ii)", position, whence); + PyObject* result = cpp_PyObject_CallMethod(file_, "seek", "(ii)", position, whence); Py_XDECREF(result); ARROW_RETURN_NOT_OK(CheckPyError()); return Status::OK(); } Status PythonFile::Read(int64_t nbytes, PyObject** out) { - PyObject* result = PyObject_CallMethod(file_, "read", "(i)", nbytes); + PyObject* result = cpp_PyObject_CallMethod(file_, "read", "(i)", nbytes); ARROW_RETURN_NOT_OK(CheckPyError()); *out = result; return Status::OK(); @@ -84,7 +95,7 @@ Status PythonFile::Write(const uint8_t* data, int64_t nbytes) { PyBytes_FromStringAndSize(reinterpret_cast<const char*>(data), nbytes); ARROW_RETURN_NOT_OK(CheckPyError()); - PyObject* result = PyObject_CallMethod(file_, "write", "(O)", py_data); + PyObject* result = cpp_PyObject_CallMethod(file_, "write", "(O)", py_data); Py_XDECREF(py_data); Py_XDECREF(result); ARROW_RETURN_NOT_OK(CheckPyError()); @@ -92,7 +103,7 @@ Status PythonFile::Write(const uint8_t* data, int64_t nbytes) { } Status PythonFile::Tell(int64_t* position) { - PyObject* result = PyObject_CallMethod(file_, "tell", "()"); + PyObject* result = cpp_PyObject_CallMethod(file_, "tell", "()"); ARROW_RETURN_NOT_OK(CheckPyError()); *position = PyLong_AsLongLong(result);
