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)
Optional follow-up in
[2f35759](https://github.com/apache/arrow/pull/50325/commits/2f35759533ba83986d9d3938b45eb96186929574):
Simplified UuidFromBytes signature by dropping the args param since it's
always empty and used `Py_GetConstantBorrowed(Py_CONSTANT_EMPTY_TUPLE)` within.
That's 3.13+ but `pythoncapi_compat.h` backports it so older versions are
covered. Totally fine to revert if not preferred
Also force-pushed to remove a VS Code workspace file I committed by accident.
--
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]