Skip to content

pysparky.functions.math_

Functions

NameDescription
cumsumCalculate the cumulative sum of a column, optionally partitioned by other columns.
haversine_distanceCalculates the Haversine distance between two sets of latitude and longitude coordinates.
sumifReturn a conditional sum using Spark expressions.

cumsumfunction#

def cumsum(column_or_name: ColumnOrName, partition_by: list[Column] | None = None, order_by_column: Column | None = None, is_normalized: bool = False, is_descending: bool = False, alias: str = 'cumsum') -> Column

Calculate the cumulative sum of a column, optionally partitioned by other columns.

Parameters

NameTypeDefaultDescription
column_or_nameColumnrequiredThe column for which to calculate the cumulative sum.
partition_bylist[Column]NoneA list of columns to partition by. Defaults to an empty list.
order_by_columnColumn | NoneNoneThe Column for order by, null for using the same column.
is_normalizedboolFalseWhether to normalize the cumulative sum. Defaults to False.
is_descendingboolFalseWhether to order the cumulative sum in descending order. Defaults to False.
aliasstr'cumsum'Alias for the resulting column. Defaults to “cumsum”.

Returns

ColumnColumn
A column representing the cumulative sum.

haversine_distancefunction#

def haversine_distance(lat1: ColumnOrName, long1: ColumnOrName, lat2: ColumnOrName, long2: ColumnOrName) -> Column

Calculates the Haversine distance between two sets of latitude and longitude coordinates.

Parameters

NameTypeDescription
lat1ColumnOrNameThe column containing the latitude of the first coordinate.
long1ColumnOrNameThe column containing the longitude of the first coordinate.
lat2ColumnOrNameThe column containing the latitude of the second coordinate.
long2ColumnOrNameThe column containing the longitude of the second coordinate.

Returns

ColumnColumn
The column containing the calculated Haversine distance.

sumiffunction#

def sumif(condition: Column, value: Union[Column, int, float] = 1, otherwise_value: Union[Column, int, float] = 0) -> Column

Return a conditional sum using Spark expressions.

Parameters

NameTypeDefaultDescription
conditionColumnrequiredBoolean Spark expression to filter rows.
valueUnion[Column, int, float]1Column or scalar to sum when condition is True.
otherwise_valueUnion[Column, int, float]0Column or scalar to use when condition is False.

Returns

ColumnColumn
Spark aggregation expression that sums value when true,
Column
otherwise otherwise_value.