rok commented on code in PR #48727:
URL: https://github.com/apache/arrow/pull/48727#discussion_r2698973501


##########
python/pyarrow/src/arrow/python/python_to_arrow.cc:
##########
@@ -512,7 +513,12 @@ class PyValue {
 
   static Status Convert(const FixedSizeBinaryType* type, const O&, I obj,
                         PyBytesView& view) {
-    ARROW_RETURN_NOT_OK(view.ParseString(obj));
+    // Check if obj is a uuid.UUID instance
+    if (type->byte_width() == 16 && internal::IsPyUuid(obj)) {

Review Comment:
   A nit: it seems `uuid.UUID` can't have other bitwidths, so we don't really 
need the `type->byte_width() == 16` check.



##########
python/pyarrow/src/arrow/python/helpers.cc:
##########
@@ -296,6 +296,67 @@ bool PyFloat_IsNaN(PyObject* obj) {
 
 namespace {
 
+// UUID module static data - lazily initialized on first use
+// Uses a conditional initialization strategy: std::once_flag when the GIL is
+// disabled, or a simple boolean flag when the GIL is enabled.
+// See the Pandas static data section below and ARROW-10519 for more details.
+#ifdef Py_GIL_DISABLED
+static std::once_flag uuid_static_initialized;
+#else
+static bool uuid_static_initialized = false;
+#endif
+static PyObject* uuid_UUID = nullptr;
+
+void GetUuidStaticSymbols() {
+  OwnedRef uuid_module;
+
+  // Import uuid module
+  Status s = ImportModule("uuid", &uuid_module);
+  if (!s.ok()) {
+    return;
+  }
+
+#ifndef Py_GIL_DISABLED
+  if (uuid_static_initialized) {
+    return;
+  }
+#endif
+
+  OwnedRef ref;
+  if (ImportFromModule(uuid_module.obj(), "UUID", &ref).ok()) {
+    uuid_UUID = ref.obj();
+  }
+}
+
+#ifdef Py_GIL_DISABLED
+void InitUuidStaticData() {
+  std::call_once(uuid_static_initialized, GetUuidStaticSymbols);
+}
+#else
+void InitUuidStaticData() {
+  if (uuid_static_initialized) {
+    return;
+  }
+  GetUuidStaticSymbols();
+  uuid_static_initialized = true;
+}
+#endif

Review Comment:
   Perhaps we could use `std::call_once` for both cases here?



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