jorisvandenbossche commented on a change in pull request #12010:
URL: https://github.com/apache/arrow/pull/12010#discussion_r781223239
##########
File path: python/pyarrow/table.pxi
##########
@@ -1016,6 +1065,21 @@ cdef class RecordBatch(_PandasConvertible):
entries.append((name, column))
return ordered_dict(entries)
+ def to_pylist(self):
+ """
+ Convert the RecordBatch to a list of rows / dictionaries.
+
+ Returns
+ -------
+ list
+ """
+
+ pydict = self.to_pydict()
+ names = self.schema.names
+ pylist = [{column: pydict[column][row] if column in pydict else None
for column in names}
+ for row in range(self.num_rows)]
Review comment:
```suggestion
pylist = [{column: pydict[column][row] for column in names}
for row in range(self.num_rows)]
```
I think this can be simplified now, as each `column` value of `names` is
guaranteed to be in the `pydict`, since `names` is coming from the schema.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]