xinrong-databricks commented on code in PR #36793: URL: https://github.com/apache/spark/pull/36793#discussion_r894695373
########## python/pyspark/sql/session.py: ########## @@ -952,12 +953,29 @@ def createDataFrame( # type: ignore[misc] schema = [x.encode("utf-8") if not isinstance(x, str) else x for x in schema] try: - import pandas + import pandas as pd has_pandas = True except Exception: has_pandas = False - if has_pandas and isinstance(data, pandas.DataFrame): + + try: + import numpy as np + + has_numpy = True + except Exception: + has_numpy = False + + if has_numpy and isinstance(data, np.ndarray): + from pyspark.sql.pandas.utils import require_minimum_pandas_version + + require_minimum_pandas_version() + if data.ndim not in [1, 2]: + raise ImportError("NumPy array input should be of 1 or 2 dimensions.") + column_names = ["value"] if data.ndim == 1 else ["_1", "_2"] Review Comment: We seem to infer the schema of the input list from the first element only. To support `spark.createDataFrame([1, 2])`, we may assume the elements in the list are of the same type. Is that acceptable? -- 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-unsubscr...@spark.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org