Skip to content

Commit

Permalink
[MINOR][DOCS] Improve clarity in lag docstring
Browse files Browse the repository at this point in the history
  • Loading branch information
thomash-dbx committed Jul 5, 2024
1 parent f1eca90 commit 7a03428
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions python/pyspark/sql/functions/builtin.py
Original file line number Diff line number Diff line change
Expand Up @@ -6944,29 +6944,29 @@ def lag(col: "ColumnOrName", offset: int = 1, default: Optional[Any] = None) ->
| b| 2|
+---+---+
>>> w = Window.partitionBy("c1").orderBy("c2")
>>> df.withColumn("previos_value", lag("c2").over(w)).show()
>>> df.withColumn("previous_value", lag("c2").over(w)).show()
+---+---+-------------+
| c1| c2|previos_value|
| c1| c2|previous_value|
+---+---+-------------+
| a| 1| NULL|
| a| 2| 1|
| a| 3| 2|
| b| 2| NULL|
| b| 8| 2|
+---+---+-------------+
>>> df.withColumn("previos_value", lag("c2", 1, 0).over(w)).show()
>>> df.withColumn("previous_value", lag("c2", 1, 0).over(w)).show()
+---+---+-------------+
| c1| c2|previos_value|
| c1| c2|previous_value|
+---+---+-------------+
| a| 1| 0|
| a| 2| 1|
| a| 3| 2|
| b| 2| 0|
| b| 8| 2|
+---+---+-------------+
>>> df.withColumn("previos_value", lag("c2", 2, -1).over(w)).show()
>>> df.withColumn("previous_value", lag("c2", 2, -1).over(w)).show()
+---+---+-------------+
| c1| c2|previos_value|
| c1| c2|previous_value|
+---+---+-------------+
| a| 1| -1|
| a| 2| -1|
Expand Down

0 comments on commit 7a03428

Please sign in to comment.