You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2022/06/18 07:46:25 UTC

[GitHub] [spark] zhengruifeng commented on a diff in pull request #36870: [SPARK-39483][PYTHON] Construct the schema from `np.dtype` when `createDataFrame` from a NumPy array

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


##########
python/pyspark/sql/session.py:
##########
@@ -975,6 +976,17 @@ def createDataFrame(  # type: ignore[misc]
             if data.ndim not in [1, 2]:
                 raise ValueError("NumPy array input should be of 1 or 2 dimensions.")
             column_names = ["value"] if data.ndim == 1 else ["_1", "_2"]
+            if schema is None and not self._jconf.arrowPySparkEnabled():
+                # Construct `schema` from `np.dtype` of the input NumPy array
+                # TODO: Apply the logic below when self._jconf.arrowPySparkEnabled() is True
+                spark_type = _from_numpy_type(data.dtype)
+                if spark_type is not None:
+

Review Comment:
   may simplify like this
   ```schema = StructType([StructField(name, spark_type, True) for name in column_names])```
   
   as to the `nullable=True`, should we detect where a column is `nullable`?



-- 
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: reviews-unsubscribe@spark.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org