Skip to content

[Python] Scalar subclasses should implement Python protocols #45653

Closed

Description

@pitrou

Describe the enhancement requested

To make PyArrow scalars easier to use with non-PyArrow functions, we should define appropriate methods and protocols for specific scalar subclasses.

Examples:

  • integer scalars should implement __int__
  • floating-point scalars should implement __float__
  • binary scalars should implement __bytes__ and perhaps the buffer protocol
  • list-like scalars could implement Sequence
  • map scalars could implement Mapping
  • struct scalars could implement both Sequence and Mapping (?)

Note that some of this exists (unvoluntarily?) but is broken:

>>> a, b = pc.min_max([1,2,3])
>>> a  # expecting 1
'min'
>>> b  # expecting 3
'max'

Component(s)

Python

Activity

  1. pitrou commented on Mar 3, 2025

    @pitrou
    MemberAuthor
  2. self-assigned this
    on Mar 3, 2025
  3. thisisnic commented on Mar 10, 2025

    @thisisnic
    Member

    Hey folks, @AlenkaF pointed me to this issue as a good place to get started contributing to PyArrow, so I was going to take a look at this. I might be a bit slow as I'll be spending some time getting acquainted with PyArrow in general, so I was going to spend the new few weeks looking at this. If there's any urgency, happy for someone else to take it off my hands though! :)

  4. self-assigned this
    on Mar 10, 2025
  5. removed their assignment
    on Mar 10, 2025
  6. pitrou commented on Mar 10, 2025

    @pitrou
    MemberAuthor

    There's definitely no urgency here, feel free to take a stab at this!

  7. added a commit that references this issue on Jun 10, 2025
  8. added this to the 21.0.0 milestone on Jun 10, 2025
  9. pitrou commented on Jun 10, 2025

    @pitrou
    MemberAuthor

    Issue resolved by pull request 45818
    #45818

  10. added a commit that references this issue on Jun 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions