amol- commented on a change in pull request #12010:
URL: https://github.com/apache/arrow/pull/12010#discussion_r773257529



##########
File path: python/pyarrow/table.pxi
##########
@@ -2436,6 +2581,52 @@ def _from_pydict(cls, mapping, schema, metadata):
         raise TypeError('Schema must be an instance of pyarrow.Schema')
 
 
+def _from_pylist(cls, mapping, schema, metadata):
+    """
+    Construct a Table/RecordBatch from Arrow arrays or columns.
+
+    Parameters
+    ----------
+    cls : Class Table/RecordBatch
+    mapping : list of dicts or Mappings
+        A mapping of strings to Arrays or Python lists.
+    schema : Schema, default None
+        If not passed, will be inferred from the Mapping values.
+    metadata : dict or Mapping, default None
+        Optional metadata for the schema (if inferred).
+
+    Returns
+    -------
+    Table/RecordBatch
+    """
+
+    arrays = []
+    if schema is None:
+        names = []
+        for item in mapping:
+            name = list(item.keys())[0]
+            names.append(name)
+            arrays.append(asarray(item[name]))
+        return cls.from_arrays(arrays, names, metadata=metadata)
+    elif isinstance(schema, Schema):
+        for field in schema:
+            value = [v.get(field.name) for v in mapping]
+            v = next((i for i in value if i is not None), None)
+            if v is None:
+                present = [list(v.keys())[0] for v in mapping]
+                missing = [n for n in schema.names if n not in present]
+                raise KeyError(
+                    "The passed mapping doesn't contain the "
+                    "following field(s) of the schema: {}".
+                    format(', '.join(missing))
+                )

Review comment:
       I think this is a check that we should do in `from_arrays` if we want to 
do it. 




-- 
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: github-unsubscr...@arrow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to