seberg commented on code in PR #48391:
URL: https://github.com/apache/arrow/pull/48391#discussion_r2613223092
##########
python/pyarrow/src/arrow/python/numpy_to_arrow.cc:
##########
@@ -74,6 +81,37 @@ using internal::NumPyTypeSize;
namespace {
+#if NPY_ABI_VERSION >= 0x02000000
+
+// NumPy exposes StringDType helpers in the C-API table from version 2.0
onward,
+// but the corresponding macros are only available when compiling against a
+// 2.0+ feature level. Arrow still targets an older feature level, so provide
+// local wrappers that call the C-API entries directly.
+
+inline npy_string_allocator* ArrowNpyString_acquire_allocator(
+ const PyArray_StringDTypeObject* descr) {
+ using Func = npy_string_allocator* (*)(const PyArray_StringDTypeObject*);
+ auto func = reinterpret_cast<Func>(PyArray_API[316]);
+ return func(descr);
+}
+
+inline void ArrowNpyString_release_allocator(npy_string_allocator* allocator) {
+ using Func = void (*)(npy_string_allocator*);
+ auto func = reinterpret_cast<Func>(PyArray_API[318]);
+ func(allocator);
+}
+
+inline int ArrowNpyString_load(npy_string_allocator* allocator,
+ const npy_packed_static_string* packed,
+ npy_static_string* out) {
+ using Func =
+ int (*)(npy_string_allocator*, const npy_packed_static_string*,
npy_static_string*);
+ auto func = reinterpret_cast<Func>(PyArray_API[313]);
+ return func(allocator, packed, out);
+}
Review Comment:
To be clear, I am not a maintainer. But I was suggesting to make these
defines identical to NumPy when they do not exist and only use them if needed.
The point just being to make sure to stop using them in the future, since
they are e.g. not strictly guaranteed to be correct in NumPy 3.
The ABI version guard is correct but pretty meaningless to my eyes (yes its
dead code if compiling with 1.x, but not wrong code).
(Yes the numpy version may be untested for now as you don't compile with the
target version.)
--
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]