pyspark.sql.functions.sin#

pyspark.sql.functions.sin(col)[source]#

Computes sine of the input column.

New in version 1.4.0.

Changed in version 3.4.0: Supports Spark Connect.

Parameters
colColumn or column name

target column to compute on.

Returns
Column

sine of the angle, as if computed by java.lang.Math.sin()

Examples

Example 1: Compute the sine

>>> from pyspark.sql import functions as sf
>>> spark.sql(
...     "SELECT * FROM VALUES (0.0), (PI() / 2), (PI() / 4) AS TAB(value)"
... ).select("*", sf.sin("value")).show()
+------------------+------------------+
|             value|        SIN(value)|
+------------------+------------------+
|               0.0|               0.0|
|1.5707963267948...|               1.0|
|0.7853981633974...|0.7071067811865...|
+------------------+------------------+

Example 2: Compute the sine of invalid values

>>> from pyspark.sql import functions as sf
>>> spark.sql(
...     "SELECT * FROM VALUES (FLOAT('NAN')), (NULL) AS TAB(value)"
... ).select("*", sf.sin("value")).show()
+-----+----------+
|value|SIN(value)|
+-----+----------+
|  NaN|       NaN|
| NULL|      NULL|
+-----+----------+