HyukjinKwon commented on code in PR #43301:
URL: https://github.com/apache/spark/pull/43301#discussion_r1354204634
##########
python/pyspark/sql/readwriter.py:
##########
@@ -505,24 +506,71 @@ def parquet(self, *paths: str, **options:
"OptionalPrimitiveType") -> "DataFrame
.. # noqa
+ Returns
+ -------
+ :class:`DataFrame`
+ A DataFrame containing the data from the Parquet files.
+
Examples
--------
+ Create sample dataframes.
+
+ >>> df = spark.createDataFrame(
+ ... [(10, "Alice"), (15, "Bob"), (20, "Tom")], schema=["age",
"name"])
+ >>> df2 = spark.createDataFrame([(70, "Alice"), (80, "Bob")],
schema=["height", "name"])
+
Write a DataFrame into a Parquet file and read it back.
>>> import tempfile
>>> with tempfile.TemporaryDirectory() as d:
- ... # Write a DataFrame into a Parquet file
- ... spark.createDataFrame(
- ... [{"age": 100, "name": "Hyukjin Kwon"}]
- ... ).write.mode("overwrite").format("parquet").save(d)
+ ... # Write a DataFrame into a Parquet file.
+ ... df.write.mode("overwrite").format("parquet").save(d)
...
... # Read the Parquet file as a DataFrame.
- ... spark.read.parquet(d).show()
- +---+------------+
- |age| name|
- +---+------------+
- |100|Hyukjin Kwon|
- +---+------------+
+ ... spark.read.parquet(d).orderBy("name").show()
+ +---+-----+
+ |age| name|
+ +---+-----+
+ | 10|Alice|
+ | 15| Bob|
+ | 20| Tom|
+ +---+-----+
+
+ Read a Parquet file with a specific column.
+
+ >>> with tempfile.TemporaryDirectory as d:
Review Comment:
```suggestion
>>> with tempfile.TemporaryDirectory() as d:
```
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]