jorisvandenbossche commented on a change in pull request #12010:
URL: https://github.com/apache/arrow/pull/12010#discussion_r781327109



##########
File path: python/pyarrow/table.pxi
##########
@@ -1844,6 +1967,30 @@ cdef class Table(_PandasConvertible):
 
         return ordered_dict(entries)
 
+    def to_pylist(self):
+        """
+        Convert the Table to a list of rows / dictionaries.
+
+        Returns
+        -------
+        list
+
+        Examples
+        --------
+        >>> import pyarrow as pa
+        >>> table = pa.table([
+        ...     pa.array([1, 2]),
+        ...     pa.array(["a", "b"])
+        ... ], names=["int", "str"])
+        >>> table.to_pylist()
+        [{'int': 1, 'str': 'a'}, {'int': 2, 'str': 'b'}]
+        """
+        pydict = self.to_pydict()
+        names = self.schema.names
+        pylist = [{column: pydict[column][row] if column in pydict else None 
for column in names}

Review comment:
       Ah, missed on, the same simplification can be done here as well
   ```suggestion
           pylist = [{column: pydict[column][row] for column in names}
   ```




-- 
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]


Reply via email to