Skip to content

[Python] Define whether user-overridden to_pylist on Array subclasses is honored for nested children #50604

Open

Description

@viirya

In the review of #50327 it was noted (#50327 (comment)) that the bulk conversion does not consult a user-defined to_pylist override on ExtensionArray subclasses for nested children.

This was already inconsistent before #50327:

  • ListScalar.as_py called child_values.to_pylist(), so an override on a list child's class was honored;
  • StructScalar.as_py converted fields via per-element Scalars, so an override on a struct child's class was ignored.

Top-level overrides dispatch normally through Python method resolution in both the old and the new code, and ExtensionScalar.as_py / __arrow_ext_scalar_class__ — the documented customization point — is honored on all paths.

This issue is to decide the contract:

  1. document that nested to_pylist overrides are not consulted (only ExtensionScalar.as_py is), or
  2. detect custom to_pylist overrides and route nested conversion through them (sketch in the linked discussion).

Activity

  1. Abhinav0905 commented on Aug 17, 2026

    @Abhinav0905

    I can work on a prototype once the intended contract is confirmed. My initial preference is option 1: keep ExtensionScalar.as_py as the nested customization point, treat an Array.to_pylist override as top-level behavior, and document that distinction explicitly. I would add parity tests covering extension children under both list and struct parents so the behavior is consistent rather than accidental.

    That approach also keeps the bulk conversion path fast. If option 2 is preferred, I can instead prototype explicit override detection and benchmark nested conversion to quantify the dispatch cost. Would maintainers prefer the documented scalar-customization contract or preservation of nested array overrides?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions