-
Notifications
You must be signed in to change notification settings - Fork 4k
GH-48241: [Python] Scalar inferencing doesn't infer UUID #48727
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -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() { | ||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
| if (uuid_static_initialized) { | ||||||||||
| return; | ||||||||||
| } | ||||||||||
| GetUuidStaticSymbols(); | ||||||||||
| uuid_static_initialized = true; | ||||||||||
| } | ||||||||||
| #endif | ||||||||||
|
Comment on lines
+332
to
+343
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps we could use
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see! Perhaps add this permalink then? Or just indicate this is happening in a comment. |
||||||||||
|
|
||||||||||
| } // namespace | ||||||||||
|
|
||||||||||
| bool IsPyUuid(PyObject* obj) { | ||||||||||
| InitUuidStaticData(); | ||||||||||
| if (!uuid_UUID) return false; | ||||||||||
| int result = PyObject_IsInstance(obj, uuid_UUID); | ||||||||||
| if (result < 0) { | ||||||||||
| PyErr_Clear(); | ||||||||||
| return false; | ||||||||||
| } | ||||||||||
| return result == 1; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| namespace { | ||||||||||
|
|
||||||||||
| // This needs a conditional, because using std::once_flag could introduce | ||||||||||
| // a deadlock when the GIL is enabled. See | ||||||||||
| // https://github.com/apache/arrow/commit/f69061935e92e36e25bb891177ca8bc4f463b272 for | ||||||||||
|
|
||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.