scw commented on code in PR #48258:
URL: https://github.com/apache/arrow/pull/48258#discussion_r2581993750
##########
python/pyarrow/src/arrow/python/pyarrow.cc:
##########
@@ -46,6 +46,9 @@ int import_pyarrow() {
#else
internal::InitDatetime();
#endif
+ if (PyErr_Occurred()) {
Review Comment:
@pitrou something like this?
```diff
diff --git a/python/pyarrow/src/arrow/python/datetime.cc
b/python/pyarrow/src/arrow/python/datetime.cc
index 19d4cb0a83..04ebf93278 100644
--- a/python/pyarrow/src/arrow/python/datetime.cc
+++ b/python/pyarrow/src/arrow/python/datetime.cc
@@ -77,13 +77,15 @@ static PyStructSequence_Desc MonthDayNanoTupleDesc = {
#ifndef PYPY_VERSION
PyDateTime_CAPI* datetime_api = nullptr;
-void InitDatetime() {
+int InitDatetime() {
PyAcquireGIL lock;
datetime_api =
reinterpret_cast<PyDateTime_CAPI*>(PyCapsule_Import(PyDateTime_CAPSULE_NAME,
0));
if (datetime_api == nullptr) {
PyErr_SetString(PyExc_ImportError, "Could not import datetime C API");
+ return -1;
}
+ return 0;
}
#endif
diff --git a/python/pyarrow/src/arrow/python/datetime.h
b/python/pyarrow/src/arrow/python/datetime.h
index 9b21eeb434..a5eb46a6ee 100644
--- a/python/pyarrow/src/arrow/python/datetime.h
+++ b/python/pyarrow/src/arrow/python/datetime.h
@@ -50,7 +50,7 @@ namespace internal {
extern PyDateTime_CAPI* datetime_api;
ARROW_PYTHON_EXPORT
-void InitDatetime();
+int InitDatetime();
#endif
// Returns the MonthDayNano namedtuple type (increments the reference
count).
diff --git a/python/pyarrow/src/arrow/python/pyarrow.cc
b/python/pyarrow/src/arrow/python/pyarrow.cc
index 1fa4d7ff2b..c9dc7eee21 100644
--- a/python/pyarrow/src/arrow/python/pyarrow.cc
+++ b/python/pyarrow/src/arrow/python/pyarrow.cc
@@ -44,11 +44,11 @@ int import_pyarrow() {
#ifdef PYPY_VERSION
PyDateTime_IMPORT;
#else
- internal::InitDatetime();
-#endif
- if (PyErr_Occurred()) {
- return -1;
+ auto init = internal::InitDatetime();
+ if (init == -1) {
+ return -1;
}
+#endif
return ::import_pyarrow__lib();
}
```
--
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]