parker-cassar commented on code in PR #50325:
URL: https://github.com/apache/arrow/pull/50325#discussion_r3740260508


##########
python/pyarrow/src/arrow/python/helpers.cc:
##########
@@ -338,24 +338,48 @@ struct ModuleOnceRunner {
 static PyObject* uuid_UUID = nullptr;
 static ModuleOnceRunner uuid_runner("uuid");
 
-}  // namespace
-
-bool IsPyUuid(PyObject* obj) {
+PyObject* GetUuidClass() {
   uuid_runner.RunOnce([](OwnedRef& module) {
     OwnedRef ref;
     if (ImportFromModule(module.obj(), "UUID", &ref).ok()) {
       uuid_UUID = ref.obj();
     }
   });
-  if (!uuid_UUID) return false;
-  int result = PyObject_IsInstance(obj, uuid_UUID);
+  return uuid_UUID;
+}
+
+}  // namespace
+
+bool IsPyUuid(PyObject* obj) {
+  PyObject* uuid_class = GetUuidClass();
+  if (!uuid_class) return false;
+  int result = PyObject_IsInstance(obj, uuid_class);
   if (result < 0) {
     PyErr_Clear();
     return false;
   }
   return result != 0;
 }
 
+Result<PyObject*> UuidFromBytes(std::string_view bytes) {
+  PyObject* uuid_class = GetUuidClass();
+  if (!uuid_class) {
+    return Status::Invalid("Could not import uuid.UUID");
+  }
+  OwnedRef py_bytes(
+      PyBytes_FromStringAndSize(bytes.data(), 
static_cast<Py_ssize_t>(bytes.size())));
+  RETURN_IF_PYERROR();
+  OwnedRef kwargs(PyDict_New());

Review Comment:
   Good point: kwargs now reused across a column's rows 
[ff16379](https://github.com/apache/arrow/pull/50325/commits/ff163797f2b635d43dd4b5584698cee07c0d5bf9)
   
   Minor follow-up in 
[eaf0c4b](https://github.com/apache/arrow/pull/50325/commits/eaf0c4b063155868097773fdb3cf8f8f6c1efe59):
 I swapped the empty-tuple OwnedRef args for CPython's shared singleton. 
Totally fine to revert if not preferred



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to