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/08/11 04:06:59 UTC

[GitHub] [spark] Yikun commented on a diff in pull request #37465: [SPARK-40029][PYTHON][DOC] Make pyspark.sql.types examples self-contained

Yikun commented on code in PR #37465:
URL: https://github.com/apache/spark/pull/37465#discussion_r943080421


##########
python/pyspark/sql/types.py:
##########
@@ -684,6 +702,30 @@ class StructType(DataType):
     ...     StructField("f2", IntegerType(), False)])
     >>> struct1 == struct2
     False
+
+    The below example demonstrates how to create a struct using StructType & StructField on
+    DataFrame:
+
+    >>> data = [("Alice", ["Java", "Scala"]), ("Bob", ["Python", "Scala"])]
+    >>> schema = StructType([
+    ...     StructField("name", StringType()),
+    ...     StructField("languagesSkills", ArrayType(StringType())),
+    ... ])
+    >>> df = spark.createDataFrame(data=data, schema=schema)
+    >>> df.printSchema()
+    root
+     |-- name: string (nullable = true)
+     |-- languagesSkills: array (nullable = true)
+     |    |-- element: string (containsNull = true)
+    <BLANKLINE>

Review Comment:
   ah, good suggestion, it was copy from other existing code. Addressed!
   
   and I will also submit a PR to address other places
   
   ```
   spark git:(type) ✗ grep -r BLANKLINE **/*.py
   python/pyspark/ml/stat.py:    <BLANKLINE>
   python/pyspark/ml/stat.py:    <BLANKLINE>
   python/pyspark/ml/stat.py:    <BLANKLINE>
   python/pyspark/ml/stat.py:    <BLANKLINE>
   python/pyspark/mllib/tree.py:        <BLANKLINE>
   python/pyspark/mllib/tree.py:        <BLANKLINE>
   python/pyspark/mllib/tree.py:        <BLANKLINE>
   python/pyspark/mllib/tree.py:        <BLANKLINE>
   python/pyspark/mllib/tree.py:        <BLANKLINE>
   python/pyspark/pandas/frame.py:        <BLANKLINE>
   python/pyspark/pandas/series.py:        <BLANKLINE>
   python/pyspark/pandas/series.py:        <BLANKLINE>
   python/pyspark/pandas/series.py:        <BLANKLINE>
   python/pyspark/pandas/series.py:        <BLANKLINE>
   python/pyspark/sql/dataframe.py:        <BLANKLINE>
   ```



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