You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spark.apache.org by ma...@apache.org on 2022/07/11 10:27:01 UTC
[spark] branch master updated: [MINOR][SQL] Add docstring for function pyspark.sql.functions.timestamp_seconds
This is an automated email from the ASF dual-hosted git repository.
maxgekk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/spark.git
The following commit(s) were added to refs/heads/master by this push:
new 775b5ced70c [MINOR][SQL] Add docstring for function pyspark.sql.functions.timestamp_seconds
775b5ced70c is described below
commit 775b5ced70c87d6a8709f44eb4a5de48c286a51d
Author: moritzkoerber <ko...@gmail.com>
AuthorDate: Mon Jul 11 13:26:42 2022 +0300
[MINOR][SQL] Add docstring for function pyspark.sql.functions.timestamp_seconds
### What changes were proposed in this pull request?
The documentation of the function `pyspark.sql.functions.timestamp_seconds` currently features an example but no text describing the function. This PR adds the missing text based on the docstring of `pyspark.sql.functions.from_unixtime`.
### Why are the changes needed?
The docstring is currently missing.
### Does this PR introduce _any_ user-facing change?
Yes, this PR adds a docstring that will be published in Spark's documentation.
### How was this patch tested?
No tests were added because this PR just adds text in a docstring.
Closes #36944 from moritzkoerber/add-timestamps_seconds-docstring.
Lead-authored-by: moritzkoerber <ko...@gmail.com>
Co-authored-by: Moritz Körber <mo...@tado.com>
Signed-off-by: Max Gekk <ma...@gmail.com>
---
R/pkg/R/functions.R | 6 ++++--
python/pyspark/sql/functions.py | 10 ++++++++--
sql/core/src/main/scala/org/apache/spark/sql/functions.scala | 3 ++-
3 files changed, 14 insertions(+), 5 deletions(-)
diff --git a/R/pkg/R/functions.R b/R/pkg/R/functions.R
index 1377f0daa73..d772c9bd4e4 100644
--- a/R/pkg/R/functions.R
+++ b/R/pkg/R/functions.R
@@ -3256,7 +3256,8 @@ setMethod("format_string", signature(format = "character", x = "Column"),
#' tmp <- mutate(df, to_unix = unix_timestamp(df$time),
#' to_unix2 = unix_timestamp(df$time, 'yyyy-MM-dd HH'),
#' from_unix = from_unixtime(unix_timestamp(df$time)),
-#' from_unix2 = from_unixtime(unix_timestamp(df$time), 'yyyy-MM-dd HH:mm'))
+#' from_unix2 = from_unixtime(unix_timestamp(df$time), 'yyyy-MM-dd HH:mm'),
+#' timestamp_from_unix = timestamp_seconds(unix_timestamp(df$time)))
#' head(tmp)}
#' @note from_unixtime since 1.5.0
setMethod("from_unixtime", signature(x = "Column"),
@@ -4854,7 +4855,8 @@ setMethod("current_timestamp",
})
#' @details
-#' \code{timestamp_seconds}: Creates timestamp from the number of seconds since UTC epoch.
+#' \code{timestamp_seconds}: Converts the number of seconds from the Unix epoch
+#' (1970-01-01T00:00:00Z) to a timestamp.
#'
#' @rdname column_datetime_functions
#' @aliases timestamp_seconds timestamp_seconds,Column-method
diff --git a/python/pyspark/sql/functions.py b/python/pyspark/sql/functions.py
index 3112690cc68..db99dbfc400 100644
--- a/python/pyspark/sql/functions.py
+++ b/python/pyspark/sql/functions.py
@@ -2519,19 +2519,25 @@ def to_utc_timestamp(timestamp: "ColumnOrName", tz: "ColumnOrName") -> Column:
def timestamp_seconds(col: "ColumnOrName") -> Column:
"""
+ Converts the number of seconds from the Unix epoch (1970-01-01T00:00:00Z)
+ to a timestamp.
+
.. versionadded:: 3.1.0
Examples
--------
>>> from pyspark.sql.functions import timestamp_seconds
- >>> spark.conf.set("spark.sql.session.timeZone", "America/Los_Angeles")
+ >>> spark.conf.set("spark.sql.session.timeZone", "UTC")
>>> time_df = spark.createDataFrame([(1230219000,)], ['unix_time'])
>>> time_df.select(timestamp_seconds(time_df.unix_time).alias('ts')).show()
+-------------------+
| ts|
+-------------------+
- |2008-12-25 07:30:00|
+ |2008-12-25 15:30:00|
+-------------------+
+ >>> time_df.select(timestamp_seconds('unix_time').alias('ts')).printSchema()
+ root
+ |-- ts: timestamp (nullable = true)
>>> spark.conf.unset("spark.sql.session.timeZone")
"""
diff --git a/sql/core/src/main/scala/org/apache/spark/sql/functions.scala b/sql/core/src/main/scala/org/apache/spark/sql/functions.scala
index 814a2e472f7..c056baba8ba 100644
--- a/sql/core/src/main/scala/org/apache/spark/sql/functions.scala
+++ b/sql/core/src/main/scala/org/apache/spark/sql/functions.scala
@@ -3826,7 +3826,8 @@ object functions {
}
/**
- * Creates timestamp from the number of seconds since UTC epoch.
+ * Converts the number of seconds from the Unix epoch (1970-01-01T00:00:00Z)
+ * to a timestamp.
* @group datetime_funcs
* @since 3.1.0
*/
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@spark.apache.org
For additional commands, e-mail: commits-help@spark.apache.org