GH-40282: [Python] Use C++ type traits for is_nested function - #41709
Conversation
|
|
|
@danepitkin Hello. Does this align with the original intent? I closed the previous PR because there were too many code changes, and I've opened a new one. Please review it when you have time. Thank you! |
|
Thank you for your contribution. Unfortunately, this |
| def _is_nested(data_type): | ||
| return is_nested(data_type.id) |
There was a problem hiding this comment.
| def _is_nested(data_type): | |
| return is_nested(data_type.id) | |
| def _is_nested(data_type): | |
| # This is simply a redirect, the official API is in pyarrow.types. | |
| return is_nested(data_type.id) |
|
|
||
| cdef extern from "arrow/type_traits.h" namespace "arrow": | ||
| c_bool is_nested(Type type_id) |
There was a problem hiding this comment.
I think we can simply add is_nested together with is_primitive and is_numeric here:
Can't make this comment in form of a suggestion though, which would help finalising this PR faster.
6fb46a8 to
b1cb471
Compare
|
@AlenkaF - I had Claude rebase and apply your changes, mind giving it another review if CI is happy? |
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
The new lib._is_nested wrapper’s parameter handling is inconsistent with existing typed trait wrappers (e.g., _is_primitive) and should be adjusted for maintainability and consistency.
Review effort: Lite
Findings: 2
Open (2)
What changed in this PR
This PR updates pyarrow.types.is_nested() to delegate to Arrow C++ type traits (arrow::is_nested) instead of maintaining a Python-side _NESTED_TYPES set, aligning Python behavior with the C++ definition.
Changes:
- Replace Python
_NESTED_TYPESmembership check with a call intopyarrow.libforis_nested. - Add a new Cython-level helper (
lib._is_nested) intypes.pxito expose the C++ trait to Python. - Declare
arrow::is_nested(Type)inlibarrow.pxdso it can be called from Cython.
| File | Description |
|---|---|
| python/pyarrow/types.py | Switch is_nested implementation from Python set membership to pyarrow.lib call. |
| python/pyarrow/types.pxi | Add lib._is_nested wrapper to reach the C++ is_nested trait. |
| python/pyarrow/includes/libarrow.pxd | Expose arrow::is_nested(Type) to Cython. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The change is a low-risk refactor to reuse the existing C++ trait and existing Python tests already exercise types.is_nested() for nested and non-nested types.
Review effort: Lite
Findings: None
Resolved since last review (2)
AlenkaF
left a comment
There was a problem hiding this comment.
Yes, this looks good. Thanks for finalizing it @thisisnic!

Rationale for this change
Use C++ type traits for
is_nestedfunction to avoid redefining in PythonWhat changes are included in this PR?
Expose
is_nestedfunctionAre these changes tested?
Yes
Are there any user-facing changes?
Yes