This is an automated email from the ASF dual-hosted git repository.
AlenkaF pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow.git
The following commit(s) were added to refs/heads/main by this push:
new 12d02adf007 GH-40282: [Python] Use C++ type traits for is_nested
function (#41709)
12d02adf007 is described below
commit 12d02adf00798b6fb30fe174b8acd44e051a8a82
Author: Hyunseok Seo <[email protected]>
AuthorDate: Wed Sep 30 05:14:30 2026 -0400
GH-40282: [Python] Use C++ type traits for is_nested function (#41709)
### Rationale for this change
Use C++ type traits for `is_nested` function to avoid redefining in Python
### What changes are included in this PR?
Expose `is_nested` function
### Are these changes tested?
Yes
### Are there any user-facing changes?
Yes
* GitHub Issue: #40282
Lead-authored-by: NNic Crane <[email protected]>
Co-authored-by: Nic Crane <[email protected]>
Co-authored-by: Hyunseok Seo <[email protected]>
Signed-off-by: AlenkaF <[email protected]>
---
python/pyarrow/includes/libarrow.pxd | 1 +
python/pyarrow/types.pxi | 5 +++++
python/pyarrow/types.py | 6 +-----
3 files changed, 7 insertions(+), 5 deletions(-)
diff --git a/python/pyarrow/includes/libarrow.pxd
b/python/pyarrow/includes/libarrow.pxd
index 17dcb87a80e..296148f5281 100644
--- a/python/pyarrow/includes/libarrow.pxd
+++ b/python/pyarrow/includes/libarrow.pxd
@@ -204,6 +204,7 @@ cdef extern from "arrow/api.h" namespace "arrow" nogil:
c_bool is_primitive(Type type)
c_bool is_numeric(Type type)
+ c_bool is_nested(Type type)
cdef cppclass CArrayStatistics" arrow::ArrayStatistics":
optional[CArrayStatisticsCountType] null_count
diff --git a/python/pyarrow/types.pxi b/python/pyarrow/types.pxi
index f9530a34362..4f1bb0f652b 100644
--- a/python/pyarrow/types.pxi
+++ b/python/pyarrow/types.pxi
@@ -161,6 +161,11 @@ def _is_primitive(Type type):
return is_primitive(type)
+def _is_nested(Type type):
+ # This is simply a redirect, the official API is in pyarrow.types.
+ return is_nested(type)
+
+
def _get_pandas_type(arrow_type, coerce_to_ns=False):
cdef Type type_id = arrow_type.id
cdef dict pandas_type_map = _get_pandas_type_map()
diff --git a/python/pyarrow/types.py b/python/pyarrow/types.py
index 859bcd21abf..d2efe5d3da0 100644
--- a/python/pyarrow/types.py
+++ b/python/pyarrow/types.py
@@ -43,10 +43,6 @@ _TEMPORAL_TYPES = ({lib.Type_TIMESTAMP,
lib.Type_DURATION} | _TIME_TYPES | _DATE_TYPES |
_INTERVAL_TYPES)
_UNION_TYPES = {lib.Type_SPARSE_UNION, lib.Type_DENSE_UNION}
-_NESTED_TYPES = {lib.Type_LIST, lib.Type_FIXED_SIZE_LIST, lib.Type_LARGE_LIST,
- lib.Type_LIST_VIEW, lib.Type_LARGE_LIST_VIEW,
- lib.Type_STRUCT, lib.Type_MAP,
- lib.Type_RUN_END_ENCODED} | _UNION_TYPES
class TypesEnum(IntEnum):
@@ -257,7 +253,7 @@ def is_union(t):
@doc(is_null, datatype="nested type")
def is_nested(t):
- return t.id in _NESTED_TYPES
+ return lib._is_nested(t.id)
@doc(is_null, datatype="run-end encoded")