You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2020/10/05 13:40:43 UTC

[GitHub] [arrow] pitrou commented on a change in pull request #8312: ARROW-9941: [Python] Better string representation for extension types

pitrou commented on a change in pull request #8312:
URL: https://github.com/apache/arrow/pull/8312#discussion_r499604700



##########
File path: python/pyarrow/types.pxi
##########
@@ -697,6 +697,9 @@ cdef class ExtensionType(BaseExtensionType):
         else:
             return NotImplemented
 
+    def __str__(self):

Review comment:
       I think this can be removed now (after which the `str` test will need to be fixed).

##########
File path: cpp/src/arrow/python/extension_type.cc
##########
@@ -71,6 +72,14 @@ PyObject* DeserializeExtInstance(PyObject* type_class,
 
 static const char* kExtensionName = "arrow.py_extension_type";
 
+std::string PyExtensionType::ToString() const {
+  std::stringstream ss;
+  OwnedRef instance(GetInstance());
+  ss << "extension<" << this->extension_name() << "<" << Py_TYPE(instance.obj())->tp_name
+     << ">>";
+  return ss.str();
+}

Review comment:
       This works fine, but there is one thing missing. Since `ToString` is called from arbitrary C++ code, the GIL needs to be taken. This is achieved by adding:
   ```c++
   PyAcquireGIL lock;
   ```
   at the beginning of this method definition.
   




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org