arrow-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From w...@apache.org
Subject [1/3] arrow git commit: ARROW-461: [Python] Add Python interfaces to DictionaryArray data, pandas interop
Date Thu, 19 Jan 2017 14:27:40 GMT
Repository: arrow
Updated Branches:
  refs/heads/master 353772f84 -> 9b1b3979b


http://git-wip-us.apache.org/repos/asf/arrow/blob/9b1b3979/python/src/pyarrow/adapters/pandas.h
----------------------------------------------------------------------
diff --git a/python/src/pyarrow/adapters/pandas.h b/python/src/pyarrow/adapters/pandas.h
index 664365e..b548f93 100644
--- a/python/src/pyarrow/adapters/pandas.h
+++ b/python/src/pyarrow/adapters/pandas.h
@@ -63,11 +63,7 @@ arrow::Status ConvertTableToPandas(
     const std::shared_ptr<arrow::Table>& table, int nthreads, PyObject** out);
 
 PYARROW_EXPORT
-arrow::Status PandasMaskedToArrow(arrow::MemoryPool* pool, PyObject* ao, PyObject* mo,
-    const std::shared_ptr<arrow::Field>& field, std::shared_ptr<arrow::Array>*
out);
-
-PYARROW_EXPORT
-arrow::Status PandasToArrow(arrow::MemoryPool* pool, PyObject* ao,
+arrow::Status PandasToArrow(arrow::MemoryPool* pool, PyObject* ao, PyObject* mo,
     const std::shared_ptr<arrow::Field>& field, std::shared_ptr<arrow::Array>*
out);
 
 }  // namespace pyarrow

http://git-wip-us.apache.org/repos/asf/arrow/blob/9b1b3979/python/src/pyarrow/common.cc
----------------------------------------------------------------------
diff --git a/python/src/pyarrow/common.cc b/python/src/pyarrow/common.cc
index 0bdd289..b8712d7 100644
--- a/python/src/pyarrow/common.cc
+++ b/python/src/pyarrow/common.cc
@@ -93,7 +93,7 @@ PyBytesBuffer::PyBytesBuffer(PyObject* obj)
 }
 
 PyBytesBuffer::~PyBytesBuffer() {
-  PyGILGuard lock;
+  PyAcquireGIL lock;
   Py_DECREF(obj_);
 }
 

http://git-wip-us.apache.org/repos/asf/arrow/blob/9b1b3979/python/src/pyarrow/common.h
----------------------------------------------------------------------
diff --git a/python/src/pyarrow/common.h b/python/src/pyarrow/common.h
index 639918d..0733a3b 100644
--- a/python/src/pyarrow/common.h
+++ b/python/src/pyarrow/common.h
@@ -30,6 +30,17 @@ class MemoryPool;
 
 namespace pyarrow {
 
+class PyAcquireGIL {
+ public:
+  PyAcquireGIL() { state_ = PyGILState_Ensure(); }
+
+  ~PyAcquireGIL() { PyGILState_Release(state_); }
+
+ private:
+  PyGILState_STATE state_;
+  DISALLOW_COPY_AND_ASSIGN(PyAcquireGIL);
+};
+
 #define PYARROW_IS_PY2 PY_MAJOR_VERSION <= 2
 
 class OwnedRef {
@@ -38,7 +49,10 @@ class OwnedRef {
 
   OwnedRef(PyObject* obj) : obj_(obj) {}
 
-  ~OwnedRef() { Py_XDECREF(obj_); }
+  ~OwnedRef() {
+    PyAcquireGIL lock;
+    Py_XDECREF(obj_);
+  }
 
   void reset(PyObject* obj) {
     if (obj_ != nullptr) { Py_XDECREF(obj_); }
@@ -69,17 +83,6 @@ struct PyObjectStringify {
   }
 };
 
-class PyGILGuard {
- public:
-  PyGILGuard() { state_ = PyGILState_Ensure(); }
-
-  ~PyGILGuard() { PyGILState_Release(state_); }
-
- private:
-  PyGILState_STATE state_;
-  DISALLOW_COPY_AND_ASSIGN(PyGILGuard);
-};
-
 // TODO(wesm): We can just let errors pass through. To be explored later
 #define RETURN_IF_PYERROR()                         \
   if (PyErr_Occurred()) {                           \
@@ -88,8 +91,9 @@ class PyGILGuard {
     PyObjectStringify stringified(exc_value);       \
     std::string message(stringified.bytes);         \
     Py_DECREF(exc_type);                            \
-    Py_DECREF(exc_value);                           \
-    Py_DECREF(traceback);                           \
+    Py_XDECREF(exc_value);                          \
+    Py_XDECREF(traceback);                          \
+    PyErr_Clear();                                  \
     return Status::UnknownError(message);           \
   }
 
@@ -122,17 +126,6 @@ class PYARROW_EXPORT PyBytesBuffer : public arrow::Buffer {
   PyObject* obj_;
 };
 
-class PyAcquireGIL {
- public:
-  PyAcquireGIL() { state_ = PyGILState_Ensure(); }
-
-  ~PyAcquireGIL() { PyGILState_Release(state_); }
-
- private:
-  PyGILState_STATE state_;
-  DISALLOW_COPY_AND_ASSIGN(PyAcquireGIL);
-};
-
 }  // namespace pyarrow
 
 #endif  // PYARROW_COMMON_H

http://git-wip-us.apache.org/repos/asf/arrow/blob/9b1b3979/python/src/pyarrow/io.cc
----------------------------------------------------------------------
diff --git a/python/src/pyarrow/io.cc b/python/src/pyarrow/io.cc
index 01f851d..9235260 100644
--- a/python/src/pyarrow/io.cc
+++ b/python/src/pyarrow/io.cc
@@ -114,22 +114,22 @@ PyReadableFile::PyReadableFile(PyObject* file) {
 PyReadableFile::~PyReadableFile() {}
 
 Status PyReadableFile::Close() {
-  PyGILGuard lock;
+  PyAcquireGIL lock;
   return file_->Close();
 }
 
 Status PyReadableFile::Seek(int64_t position) {
-  PyGILGuard lock;
+  PyAcquireGIL lock;
   return file_->Seek(position, 0);
 }
 
 Status PyReadableFile::Tell(int64_t* position) {
-  PyGILGuard lock;
+  PyAcquireGIL lock;
   return file_->Tell(position);
 }
 
 Status PyReadableFile::Read(int64_t nbytes, int64_t* bytes_read, uint8_t* out) {
-  PyGILGuard lock;
+  PyAcquireGIL lock;
   PyObject* bytes_obj;
   ARROW_RETURN_NOT_OK(file_->Read(nbytes, &bytes_obj));
 
@@ -141,7 +141,7 @@ Status PyReadableFile::Read(int64_t nbytes, int64_t* bytes_read, uint8_t*
out) {
 }
 
 Status PyReadableFile::Read(int64_t nbytes, std::shared_ptr<arrow::Buffer>* out) {
-  PyGILGuard lock;
+  PyAcquireGIL lock;
 
   PyObject* bytes_obj;
   ARROW_RETURN_NOT_OK(file_->Read(nbytes, &bytes_obj));
@@ -153,7 +153,7 @@ Status PyReadableFile::Read(int64_t nbytes, std::shared_ptr<arrow::Buffer>*
out)
 }
 
 Status PyReadableFile::GetSize(int64_t* size) {
-  PyGILGuard lock;
+  PyAcquireGIL lock;
 
   int64_t current_position;
   ;
@@ -185,17 +185,17 @@ PyOutputStream::PyOutputStream(PyObject* file) {
 PyOutputStream::~PyOutputStream() {}
 
 Status PyOutputStream::Close() {
-  PyGILGuard lock;
+  PyAcquireGIL lock;
   return file_->Close();
 }
 
 Status PyOutputStream::Tell(int64_t* position) {
-  PyGILGuard lock;
+  PyAcquireGIL lock;
   return file_->Tell(position);
 }
 
 Status PyOutputStream::Write(const uint8_t* data, int64_t nbytes) {
-  PyGILGuard lock;
+  PyAcquireGIL lock;
   return file_->Write(data, nbytes);
 }
 

http://git-wip-us.apache.org/repos/asf/arrow/blob/9b1b3979/python/src/pyarrow/util/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/python/src/pyarrow/util/CMakeLists.txt b/python/src/pyarrow/util/CMakeLists.txt
index 4afb4d0..6cd49cb 100644
--- a/python/src/pyarrow/util/CMakeLists.txt
+++ b/python/src/pyarrow/util/CMakeLists.txt
@@ -20,7 +20,7 @@
 #######################################
 
 if (PYARROW_BUILD_TESTS)
-  add_library(pyarrow_test_main
+  add_library(pyarrow_test_main STATIC
 	test_main.cc)
 
   if (APPLE)

http://git-wip-us.apache.org/repos/asf/arrow/blob/9b1b3979/python/src/pyarrow/util/test_main.cc
----------------------------------------------------------------------
diff --git a/python/src/pyarrow/util/test_main.cc b/python/src/pyarrow/util/test_main.cc
index 6fb7c05..02e9a54 100644
--- a/python/src/pyarrow/util/test_main.cc
+++ b/python/src/pyarrow/util/test_main.cc
@@ -15,12 +15,22 @@
 // specific language governing permissions and limitations
 // under the License.
 
+#include <Python.h>
+
 #include <gtest/gtest.h>
 
+#include "pyarrow/do_import_numpy.h"
+#include "pyarrow/numpy_interop.h"
+
 int main(int argc, char** argv) {
   ::testing::InitGoogleTest(&argc, argv);
 
+  Py_Initialize();
+  pyarrow::import_numpy();
+
   int ret = RUN_ALL_TESTS();
 
+  Py_Finalize();
+
   return ret;
 }


Mime
View raw message