Skip to content

[Python] Implement a repr for Array and RecordBatch/Table for non-CPU data #41664

Closed

Description

@jorisvandenbossche

Currently, if you have a pyarrow Array or RecordBatch/Table object that is backed by non-CPU data, just displaying the object (__repr__) crashes, because our PrettyPrint functionality assumes it deals with data on the CPU.

At a minimum, we should make the repr not crash, for example by first checking whether we have CPU data, and if not only printing generic information (the array type or the schema) and not a preview of the data.

But, I think we could also do better by actually ensuring the repr works and is informative for non-CPU data as well. For the pretty printing part of the repr, we only need a small subset of the data (by default first and last 5 elements), and copying such portion to the CPU just for printing should generally be fine.

If we implement this on the Python side, this depends on exposing the generic CopyTo functionality (#41126) to copy to CPU device. However, we could maybe also implement this on the C++ side in PrettyPrint itself? (taking a quick look at the current implementation, I think that would require quite some refactoring, though)

Activity

  1. jorisvandenbossche commented on May 15, 2024

    @jorisvandenbossche
    MemberAuthor

    Two additional thoughts:

    • For the Table (or ChunkedArray) repr, it will actually show the first and last 5 elements of every chunk. That feels unnecessary to me, and the first 5 of the first chunk and last 5 of the last chunk seems sufficient?
    • For heavily nested data, copying 5 rows from device to host could actually be expensive because that can potentially be a lot of data. For the repr (to_string() / PrettyPrint) this is tackled by having an additional container_window to determine how many elements to print within a nested array. But I can imagine that honoring that also for deciding which data to copy will get complicated (an initial implemention just copying a slice of the actual array sounds good enough to me).
  2. added this to the 17.0.0 milestone on Jun 26, 2024
  3. jorisvandenbossche commented on Jun 26, 2024

    @jorisvandenbossche
    MemberAuthor

    Issue resolved by pull request 42010
    #42010

  4. added
    Critical FixBugfixes for security vulnerabilities, crashes, or invalid data.
    on Jul 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions