From 071209a40045a468edc3e0ce729832d8d210cf5f Mon Sep 17 00:00:00 2001 From: Hyunseok Seo Date: Fri, 17 May 2024 21:05:13 +0900 Subject: [PATCH 1/3] expose is_nested function to check type --- python/pyarrow/includes/libarrow.pxd | 3 +++ python/pyarrow/types.pxi | 4 ++++ python/pyarrow/types.py | 6 +----- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/python/pyarrow/includes/libarrow.pxd b/python/pyarrow/includes/libarrow.pxd index 455d11d39e84..42a4b5c89413 100644 --- a/python/pyarrow/includes/libarrow.pxd +++ b/python/pyarrow/includes/libarrow.pxd @@ -3348,3 +3348,6 @@ cdef extern from "arrow/python/udf.h" namespace "arrow::py" nogil: cdef extern from "arrow/compute/cast.h" namespace "arrow::compute": CResult[CDatum] Cast(const CDatum& value, const CCastOptions& options) + +cdef extern from "arrow/type_traits.h" namespace "arrow": + c_bool is_nested(Type type_id) diff --git a/python/pyarrow/types.pxi b/python/pyarrow/types.pxi index f9530a34362f..fae08ecc8e91 100644 --- a/python/pyarrow/types.pxi +++ b/python/pyarrow/types.pxi @@ -161,6 +161,10 @@ def _is_primitive(Type type): return is_primitive(type) +def _is_nested(data_type): + return is_nested(data_type.id) + + 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 859bcd21abff..b1257639afee 100644 --- a/python/pyarrow/types.py +++ b/python/pyarrow/types.py @@ -43,10 +43,6 @@ 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) @doc(is_null, datatype="run-end encoded") From b1cb471f2e7fca15131266de8a11d3ad1e394eae Mon Sep 17 00:00:00 2001 From: Nic Crane Date: Mon, 28 Sep 2026 15:02:24 +0100 Subject: [PATCH 2/3] Apply review suggestions --- python/pyarrow/includes/libarrow.pxd | 4 +--- python/pyarrow/types.pxi | 1 + 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/python/pyarrow/includes/libarrow.pxd b/python/pyarrow/includes/libarrow.pxd index 42a4b5c89413..3e0c64eead41 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 @@ -3348,6 +3349,3 @@ cdef extern from "arrow/python/udf.h" namespace "arrow::py" nogil: cdef extern from "arrow/compute/cast.h" namespace "arrow::compute": CResult[CDatum] Cast(const CDatum& value, const CCastOptions& options) - -cdef extern from "arrow/type_traits.h" namespace "arrow": - c_bool is_nested(Type type_id) diff --git a/python/pyarrow/types.pxi b/python/pyarrow/types.pxi index fae08ecc8e91..7d53c0a0c073 100644 --- a/python/pyarrow/types.pxi +++ b/python/pyarrow/types.pxi @@ -162,6 +162,7 @@ def _is_primitive(Type type): def _is_nested(data_type): + # This is simply a redirect, the official API is in pyarrow.types. return is_nested(data_type.id) From 7d5fe7b6f231f4a5827acf4d3c2a092de8789830 Mon Sep 17 00:00:00 2001 From: Nic Crane Date: Mon, 28 Sep 2026 15:26:32 +0100 Subject: [PATCH 3/3] Respond to review feedback --- python/pyarrow/types.pxi | 4 ++-- python/pyarrow/types.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/python/pyarrow/types.pxi b/python/pyarrow/types.pxi index 7d53c0a0c073..4f1bb0f652b5 100644 --- a/python/pyarrow/types.pxi +++ b/python/pyarrow/types.pxi @@ -161,9 +161,9 @@ def _is_primitive(Type type): return is_primitive(type) -def _is_nested(data_type): +def _is_nested(Type type): # This is simply a redirect, the official API is in pyarrow.types. - return is_nested(data_type.id) + return is_nested(type) def _get_pandas_type(arrow_type, coerce_to_ns=False): diff --git a/python/pyarrow/types.py b/python/pyarrow/types.py index b1257639afee..d2efe5d3da0c 100644 --- a/python/pyarrow/types.py +++ b/python/pyarrow/types.py @@ -253,7 +253,7 @@ def is_union(t): @doc(is_null, datatype="nested type") def is_nested(t): - return lib._is_nested(t) + return lib._is_nested(t.id) @doc(is_null, datatype="run-end encoded")