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/16 23:54:56 UTC
[GitHub] [spark] ueshin commented on a diff in pull request #36893: [SPARK-39494][PYTHON] Support `createDataFrame` from a list of scalars
ueshin commented on code in PR #36893:
URL: https://github.com/apache/spark/pull/36893#discussion_r899648682
##########
python/pyspark/sql/session.py:
##########
@@ -1024,7 +1024,18 @@ def prepare(obj: Any) -> Any:
if isinstance(data, RDD):
rdd, struct = self._createFromRDD(data.map(prepare), schema, samplingRatio)
else:
- rdd, struct = self._createFromLocal(map(prepare, data), schema)
+ if isinstance(data, list):
+ # Wrap each element with a tuple if there is any scalar in the list
+ has_scalar = False
+ for x in data:
+ if isinstance(x, str) or not hasattr(x, "__len__"): # Scalar
+ has_scalar = True
+ break
Review Comment:
How about:
```py
has_scalar = any(isinstance(x, str) or not hasattr(x, "__len__") for x in data)
```
?
--
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