Skip to main content

sign

Computes the signum of the given value. Supports Spark Connect.

For the corresponding Databricks SQL function, see sign function.

Syntax

Python
from pyspark.databricks.sql import functions as dbf

dbf.sign(col=<col>)

Parameters

Parameter

Type

Description

col

pyspark.sql.Column or column name

target column to compute on.

Returns

pyspark.sql.Column: the column for computed results.

Examples

Python
from pyspark.databricks.sql import functions as dbf
spark.range(1).select(
dbf.sign(dbf.lit(-5)),
dbf.sign(dbf.lit(6)),
dbf.sign(dbf.lit(float('nan'))),
dbf.sign(dbf.lit(None))
).show()
Output
+--------+-------+---------+----------+
|sign(-5)|sign(6)|sign(NaN)|sign(NULL)|
+--------+-------+---------+----------+
| -1.0| 1.0| NaN| NULL|
+--------+-------+---------+----------+