zhengruifeng commented on code in PR #39360:
URL: https://github.com/apache/spark/pull/39360#discussion_r1060487437


##########
python/pyspark/sql/connect/session.py:
##########
@@ -199,27 +200,42 @@ def createDataFrame(
             # Must re-encode any unicode strings to be consistent with 
StructField names
             _cols = [x.encode("utf-8") if not isinstance(x, str) else x for x 
in schema]
 
-        # Create the Pandas DataFrame
         if isinstance(data, pd.DataFrame):
-            pdf = data
+            table = pa.Table.from_pandas(data)
 
         elif isinstance(data, np.ndarray):
-            # `data` of numpy.ndarray type will be converted to a pandas 
DataFrame,
             if data.ndim not in [1, 2]:
                 raise ValueError("NumPy array input should be of 1 or 2 
dimensions.")
 
-            pdf = pd.DataFrame(data)
-
             if _cols is None:
                 if data.ndim == 1 or data.shape[1] == 1:
                     _cols = ["value"]
                 else:
                     _cols = ["_%s" % i for i in range(1, data.shape[1] + 1)]
 
+            if data.ndim == 1:
+                if 1 != len(_cols):
+                    raise ValueError(
+                        f"Length mismatch: Expected axis has 1 element, "
+                        f"new values have {len(_cols)} elements"
+                    )
+
+                table = pa.Table.from_arrays([pa.array(data)], _cols)
+            else:
+                if data.shape[1] != len(_cols):

Review Comment:
   add this check to make the error consistent with other branches, otherwise 
PyArrow throws an internal AssertionError.



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to