paleolimbot commented on code in PR #378:
URL: https://github.com/apache/arrow-nanoarrow/pull/378#discussion_r1491514005
##########
python/src/nanoarrow/c_lib.py:
##########
@@ -305,3 +514,101 @@ def allocate_c_array_stream():
>>> pa_reader._export_to_c(array_stream._addr())
"""
return CArrayStream.allocate()
+
+
+# This is a heuristic for detecting a pyarrow.Array or pyarrow.RecordBatch
+# for pyarrow < 14.0.0, after which the the __arrow_c_array__ protocol
+# is sufficient to detect such an array. This check can't use isinstance()
+# to avoid importing pyarrow unnecessarily.
+def _obj_is_pyarrow_array(obj):
+ obj_type = type(obj)
+ if obj_type.__module__ != "pyarrow.lib":
+ return False
+
+ if not obj_type.__name__.endswith("Array") and obj_type.__name__ !=
"RecordBatch":
+ return False
+
+ return hasattr(obj, "_export_to_c")
+
+
+def _obj_is_iterable(obj):
+ return hasattr(obj, "__iter__")
Review Comment:
I think there are some valid iterators that don't set `__len__` that we
probably want to support (although we might be able to do a better job
reserving if we do check for a len attribute).
```python
hasattr(zip(b"123", "abc"), "__len__")
#> False
hasattr((x for x in b"123"), "__len__")
#> False
```
--
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]