Skip to content

Commit

Permalink
[MINOR][PYTHON][DOCS] Fix the docstring of to_timestamp
Browse files Browse the repository at this point in the history
### What changes were proposed in this pull request?
Fix the docstring of `to_timestamp`

### Why are the changes needed?
`try_to_timestamp` is used in the examples of `to_timestamp`

### Does this PR introduce _any_ user-facing change?
doc changes

### How was this patch tested?
updated doctests

### Was this patch authored or co-authored using generative AI tooling?
no

Closes #48207 from zhengruifeng/py_doc_nit_tots.

Authored-by: Ruifeng Zheng <ruifengz@apache.org>
Signed-off-by: Hyukjin Kwon <gurwls223@apache.org>
  • Loading branch information
zhengruifeng authored and HyukjinKwon committed Sep 23, 2024
1 parent 1086256 commit 94d288e
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions python/pyspark/sql/functions/builtin.py
Original file line number Diff line number Diff line change
Expand Up @@ -9091,15 +9091,19 @@ def to_timestamp(col: "ColumnOrName", format: Optional[str] = None) -> Column:
:class:`~pyspark.sql.Column`
timestamp value as :class:`pyspark.sql.types.TimestampType` type.

See Also
--------
:meth:`pyspark.sql.functions.try_to_timestamp`

Examples
--------
Example 1: Convert string to a timestamp

>>> import pyspark.sql.functions as sf
>>> df = spark.createDataFrame([('1997-02-28 10:30:00',)], ['t'])
>>> df.select(sf.try_to_timestamp(df.t).alias('dt')).show()
>>> df.select(sf.to_timestamp(df.t)).show()
+-------------------+
| dt|
| to_timestamp(t)|
+-------------------+
|1997-02-28 10:30:00|
+-------------------+
Expand All @@ -9108,12 +9112,12 @@ def to_timestamp(col: "ColumnOrName", format: Optional[str] = None) -> Column:

>>> import pyspark.sql.functions as sf
>>> df = spark.createDataFrame([('1997-02-28 10:30:00',)], ['t'])
>>> df.select(sf.try_to_timestamp(df.t, sf.lit('yyyy-MM-dd HH:mm:ss')).alias('dt')).show()
+-------------------+
| dt|
+-------------------+
|1997-02-28 10:30:00|
+-------------------+
>>> df.select(sf.to_timestamp(df.t, 'yyyy-MM-dd HH:mm:ss')).show()
+------------------------------------+
|to_timestamp(t, yyyy-MM-dd HH:mm:ss)|
+------------------------------------+
| 1997-02-28 10:30:00|
+------------------------------------+
"""
from pyspark.sql.classic.column import _to_java_column

Expand All @@ -9139,6 +9143,10 @@ def try_to_timestamp(col: "ColumnOrName", format: Optional["ColumnOrName"] = Non
format: str, optional
format to use to convert timestamp values.

See Also
--------
:meth:`pyspark.sql.functions.to_timestamp`

Examples
--------
Example 1: Convert string to a timestamp
Expand Down

0 comments on commit 94d288e

Please sign in to comment.