Skip to content

GH-40282: [Python] Use C++ type traits for is_nested function - #41709

Merged
AlenkaF merged 3 commits into
apache:mainfrom
llama90:ARROW-40282-for-only-nested-types
Sep 30, 2026
Merged

AlenkaF merged 3 commits into
apache:mainfrom
llama90:ARROW-40282-for-only-nested-types

Conversation

@llama90

@llama90 llama90 commented May 17, 2024 •

Copy link
Copy Markdown
Contributor

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-actions

Copy link
Copy Markdown

⚠️ GitHub issue #40282 has been automatically assigned in GitHub to PR creator.

@llama90

llama90 commented May 17, 2024

Copy link
Copy Markdown
Contributor Author

@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!

@llama90

llama90 commented Jun 5, 2024

Copy link
Copy Markdown
Contributor Author

@AlenkaF @pitrou Does this align with the original intent? Please review it when you have time. Thank you!

@github-actions github-actions Bot added the Status: stale-warning Issues and PRs flagged as stale which are due to be closed if no indication otherwise label Nov 18, 2025
@thisisnic

Copy link
Copy Markdown
Member

Thank you for your contribution. Unfortunately, this
pull request has been marked as stale because it has had no activity in the past 365 days. Please remove the stale label
or comment below, or this PR will be closed in 14 days. Feel free to re-open this if it has been closed in error. If you
do not have repository permissions to reopen the PR, please tag a maintainer.

@AlenkaF AlenkaF left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for not responding to you contribution of such a long time @llama90!
I only have two suggestions otherwise the changes look good to me.

Would you be able to add changes? Otherwise I can push and merge. Thanks!

Comment thread python/pyarrow/types.pxi Outdated
Comment on lines +150 to +151
def _is_nested(data_type):
return is_nested(data_type.id)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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)

Comment thread python/pyarrow/includes/libarrow.pxd Outdated
Comment on lines +3029 to +3031

cdef extern from "arrow/type_traits.h" namespace "arrow":
c_bool is_nested(Type type_id)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can simply add is_nested together with is_primitive and is_numeric here:

https://github.com/apache/arrow/blob/a15803601f439b110ba676fa5ba28473e50f50bc/python/pyarrow/includes/libarrow.pxd#L205C12-L206

Can't make this comment in form of a suggestion though, which would help finalising this PR faster.

@AlenkaF AlenkaF removed the Status: stale-warning Issues and PRs flagged as stale which are due to be closed if no indication otherwise label Nov 19, 2025
@github-actions github-actions Bot added awaiting committer review Awaiting committer review and removed awaiting review Awaiting review labels Nov 19, 2025
@thisisnic
thisisnic force-pushed the ARROW-40282-for-only-nested-types branch from 6fb46a8 to b1cb471 Compare September 28, 2026 14:03
Copilot AI lite review requested due to automatic review settings September 28, 2026 14:03
@thisisnic

Copy link
Copy Markdown
Member

@AlenkaF - I had Claude rebase and apply your changes, mind giving it another review if CI is happy?

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 Low severity

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_TYPES membership check with a call into pyarrow.lib for is_nested.
  • Add a new Cython-level helper (lib._is_nested) in types.pxi to expose the C++ trait to Python.
  • Declare arrow::is_nested(Type) in libarrow.pxd so 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.

Comment thread python/pyarrow/types.pxi Outdated
Comment thread python/pyarrow/types.py Outdated
Copilot AI review requested due to automatic review settings September 28, 2026 14:27

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 AlenkaF left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this looks good. Thanks for finalizing it @thisisnic!

@AlenkaF
AlenkaF merged commit 12d02ad into apache:main Sep 30, 2026
39 checks passed
@AlenkaF AlenkaF removed the awaiting committer review Awaiting committer review label Sep 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants