You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spark.apache.org by gu...@apache.org on 2023/12/08 07:59:09 UTC

(spark) branch master updated: [SPARK-46323][PYTHON] Fix the output name of pyspark.sql.functions.now

This is an automated email from the ASF dual-hosted git repository.

gurwls223 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 e76eb9fa4c42 [SPARK-46323][PYTHON] Fix the output name of pyspark.sql.functions.now
e76eb9fa4c42 is described below

commit e76eb9fa4c42da4237e282ce4da8e3e8d1be38ba
Author: Hyukjin Kwon <gu...@apache.org>
AuthorDate: Fri Dec 8 16:58:52 2023 +0900

    [SPARK-46323][PYTHON] Fix the output name of pyspark.sql.functions.now
    
    ### What changes were proposed in this pull request?
    
    This PR proposes to fix `current_timestamp()` to `now()` in its output name when you invoke `pyspark.sql.functions.now`.
    
    ### Why are the changes needed?
    
    To show the correct name of the functions being used.
    
    ### Does this PR introduce _any_ user-facing change?
    
    Yes.
    
    ```python
    from pyspark.sql import functions as sf
    df.select(sf.now()).show(truncate=False)
    ```
    
    Before:
    
    ```
    +--------------------------+
    |current_timestamp()       |
    +--------------------------+
    |2023-12-08 15:15:58.767781|
    +--------------------------+
    ```
    
    After:
    
    ```
    +--------------------------+
    |now()                     |
    +--------------------------+
    |2023-12-08 15:18:18.482269|
    +--------------------------+
    ```
    
    ### How was this patch tested?
    
    Manually tested, and unittests were added.
    
    ### Was this patch authored or co-authored using generative AI tooling?
    
    No.
    
    Closes #44252 from HyukjinKwon/now-name.
    
    Authored-by: Hyukjin Kwon <gu...@apache.org>
    Signed-off-by: Hyukjin Kwon <gu...@apache.org>
---
 python/pyspark/sql/connect/functions/builtin.py |  2 +-
 python/pyspark/sql/functions/builtin.py         | 15 ++++++++-------
 python/pyspark/sql/tests/test_functions.py      |  8 ++++++++
 3 files changed, 17 insertions(+), 8 deletions(-)

diff --git a/python/pyspark/sql/connect/functions/builtin.py b/python/pyspark/sql/connect/functions/builtin.py
index 48a7a223e6e4..cf2e2e0c7344 100644
--- a/python/pyspark/sql/connect/functions/builtin.py
+++ b/python/pyspark/sql/connect/functions/builtin.py
@@ -2864,7 +2864,7 @@ current_timestamp.__doc__ = pysparkfuncs.current_timestamp.__doc__
 
 
 def now() -> Column:
-    return _invoke_function("current_timestamp")
+    return _invoke_function("now")
 
 
 now.__doc__ = pysparkfuncs.now.__doc__
diff --git a/python/pyspark/sql/functions/builtin.py b/python/pyspark/sql/functions/builtin.py
index 87ae84c4e2d4..4f8e6a8e1d14 100644
--- a/python/pyspark/sql/functions/builtin.py
+++ b/python/pyspark/sql/functions/builtin.py
@@ -6838,15 +6838,16 @@ def now() -> Column:
 
     Examples
     --------
+    >>> from pyspark.sql import functions as sf
     >>> df = spark.range(1)
-    >>> df.select(now()).show(truncate=False) # doctest: +SKIP
-    +-----------------------+
-    |now()    |
-    +-----------------------+
-    |2022-08-26 21:23:22.716|
-    +-----------------------+
+    >>> df.select(sf.now()).show(truncate=False) # doctest: +SKIP
+    +--------------------------+
+    |now()                     |
+    +--------------------------+
+    |2023-12-08 15:18:18.482269|
+    +--------------------------+
     """
-    return _invoke_function("current_timestamp")
+    return _invoke_function("now")
 
 
 @_try_remote_functions
diff --git a/python/pyspark/sql/tests/test_functions.py b/python/pyspark/sql/tests/test_functions.py
index 2ac7ddbcba59..8586fac4e86d 100644
--- a/python/pyspark/sql/tests/test_functions.py
+++ b/python/pyspark/sql/tests/test_functions.py
@@ -1376,6 +1376,14 @@ class FunctionsTestsMixin:
         for i in range(3):
             self.assertEqual(res[0][i * 2], res[0][i * 2 + 1])
 
+    def test_current_timestamp(self):
+        df = self.spark.range(1).select(F.current_timestamp())
+        self.assertIsInstance(df.first()[0], datetime.datetime)
+        self.assertEqual(df.schema.names[0], "current_timestamp()")
+        df = self.spark.range(1).select(F.now())
+        self.assertIsInstance(df.first()[0], datetime.datetime)
+        self.assertEqual(df.schema.names[0], "now()")
+
 
 class FunctionsTests(ReusedSQLTestCase, FunctionsTestsMixin):
     pass


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@spark.apache.org
For additional commands, e-mail: commits-help@spark.apache.org