Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Ruby] Provide an equivalent of Pyarrow's .to_pylist #45122

Open
fpacanowski opened this issue Dec 29, 2024 · 1 comment
Open

[Ruby] Provide an equivalent of Pyarrow's .to_pylist #45122

fpacanowski opened this issue Dec 29, 2024 · 1 comment

Comments

@fpacanowski
Copy link

Describe the enhancement requested

In certain use cases it's quite useful to convert a RecordBatch or a Table to an array of hashes, e.g. when using Parquet for data exchange. Pyarrow provides this functionality as to_pylist function.

Basically I'd love to see an inverse of Arrow::RecordBatchBuilder.build.

rb = Arrow::RecordBatchBuilder.build(schema, data)
assert rb.to_pylist == data

Additionally it would be great if it correctly handled struct and list data type, for example:

schema = Arrow::Schema.new([
  Arrow::Field.new("c1", :int32),
  Arrow::Field.new("c2",
    Arrow::StructDataType.new([
      Arrow::Field.new("c3", :int32),
      Arrow::Field.new("c4",
        Arrow::StructDataType.new([
          Arrow::Field.new("c5", :int32),
          Arrow::Field.new("c6", Arrow::ListDataType.new(:int32)),
        ])
      )
    ])
  )
])

data = [
    {c1: 1, c2: {c3: 3, c4: {c5: 5, c6: [6, 7]}}},
    {c1: 11, c2: {c3: 13, c4: {c5: 15, c6: [16, 17]}}},
]
rb = Arrow::RecordBatchBuilder.build(schema, data)
assert rb.to_pylist == data

(Obviously the method wouldn't be named to_pylist.)

Component(s)

Ruby

@kou
Copy link
Member

kou commented Dec 31, 2024

We have Arrow::RecordBatch#raw_records/Arrow::Table#raw_records and #each_raw_record.
But they don't add keys: [1, {"c3" => 3, "c4" => {"c5" => 5, "c6" => [6, 7]}}]

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

No branches or pull requests

2 participants