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/21 18:55:55 UTC

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

xinrong-databricks commented on code in PR #36870:
URL: https://github.com/apache/spark/pull/36870#discussion_r902961587


##########
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:
   Good idea! Simplified.
   
   As for `nullable`, shall we follow how we infer schema, as [here](https://github.com/apache/spark/blob/b588d070ebc234280af730c8f9915e8859b1886e/python/pyspark/sql/types.py#L1348)?
   
   Let me know if you have other concerns.



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