Skip to content

pysparky.functions.conditions

Functions

NameDescription
condition_andCombines multiple conditions using logical AND.
condition_orCombines multiple conditions using logical OR.
is_all_numbers_onlyChecks if the given column or string contains only numeric characters.
is_array_monotonicCheck if an array column is monotonic according to a comparator and a NULL policy.
is_array_non_decreasingCheck if an array column is non-decreasing.
is_array_non_increasingCheck if an array column is non-increasing.
is_array_strictly_decreasingCheck if an array column is strictly decreasing.
is_array_strictly_increasingCheck if an array column is strictly increasing.
is_n_character_onlyChecks if the given column or string contains exactly n alphabetic characters.
is_n_numbers_onlyChecks if the given column or string contains exactly n numeric characters.
is_printable_onlyChecks if the given column or string contains only printable characters.
is_two_character_onlyChecks if the given column or string contains exactly two alphabetic characters (either lowercase or uppercase).
startswithsCreates a PySpark Column expression to check if the given column starts with any string in the list.

condition_andfunction#

def condition_and(*conditions: ColumnOrName) -> Column

Combines multiple conditions using logical AND.

Parameters

NameTypeDefaultDescription
*conditionsColumnOrName()Multiple PySpark Column objects or SQL expression strings representing conditions.

Returns

ColumnColumn
A single PySpark Column object representing the combined condition.

condition_orfunction#

def condition_or(*conditions: ColumnOrName) -> Column

Combines multiple conditions using logical OR.

Parameters

NameTypeDefaultDescription
*conditionsColumnOrName()Multiple PySpark Column objects or SQL expression strings representing conditions.

Returns

ColumnColumn
A single PySpark Column object representing the combined condition.

is_all_numbers_onlyfunction#

def is_all_numbers_only(column_or_name) -> Column

Checks if the given column or string contains only numeric characters.

Parameters

NameTypeDescription
column_or_nameColumnOrNameThe column or string to be checked.

Returns

ColumnColumn
A column of boolean values indicating whether each entry contains only numeric characters.

is_array_monotonicfunction#

def is_array_monotonic(col: ColumnOrName, cmp_fn: Callable, null_policy: str = 'forbid') -> Column

Check if an array column is monotonic according to a comparator and a NULL policy.

Parameters

NameTypeDefaultDescription
colColumnOrNamerequiredArray column to check.
cmp_fncallablerequiredBinary function (x, y) -> Column[bool]-like. Typical choices: operator.lt # strictly increasing operator.le # non-decreasing operator.gt # strictly decreasing operator.ge # non-increasing
null_policystr'forbid'

How to treat NULL elements inside the array:

  • “forbid” : any NULL inside the array makes the result False
  • “ignore” : drop all NULLs before checking monotonicity
  • “allow_first” : allow multiple NULLs at the first positions (ignored in check)
  • “allow_last” : allow multiple NULLs at the last positions (ignored in check)
  • “allow_ends” : allow multiple NULLs at the first and/or last positions

Returns

ColumnColumn
Boolean column: True if the array is monotonic under the chosen comparator
Column
and NULL policy. Empty / single-element arrays return True.

is_array_non_decreasingfunction#

def is_array_non_decreasing(col: ColumnOrName, null_policy: str = 'forbid') -> Column

Check if an array column is non-decreasing.

Parameters

NameTypeDefaultDescription
colColumnOrNamerequiredArray column to check
null_policystr'forbid'How to treat NULL elements inside the array.

Returns

ColumnColumn
Boolean column: True if the array is non-decreasing, False otherwise.

is_array_non_increasingfunction#

def is_array_non_increasing(col: ColumnOrName, null_policy: str = 'forbid') -> Column

Check if an array column is non-increasing.

Parameters

NameTypeDefaultDescription
colColumnOrNamerequiredArray column to check
null_policystr'forbid'How to treat NULL elements inside the array.

Returns

ColumnColumn
Boolean column: True if the array is non-increasing, False otherwise.

is_array_strictly_decreasingfunction#

def is_array_strictly_decreasing(col: ColumnOrName, null_policy: str = 'forbid') -> Column

Check if an array column is strictly decreasing.

Parameters

NameTypeDefaultDescription
colColumnOrNamerequiredArray column to check
null_policystr'forbid'How to treat NULL elements inside the array.

Returns

ColumnColumn
Boolean column: True if the array is strictly decreasing, False otherwise.

is_array_strictly_increasingfunction#

def is_array_strictly_increasing(col: ColumnOrName, null_policy: str = 'forbid') -> Column

Check if an array column is strictly increasing.

Parameters

NameTypeDefaultDescription
colColumnOrNamerequiredArray column to check
null_policystr'forbid'How to treat NULL elements inside the array.

Returns

ColumnColumn
Boolean column: True if the array is strictly increasing, False otherwise.

is_n_character_onlyfunction#

def is_n_character_only(column_or_name: ColumnOrName, n: int) -> Column

Checks if the given column or string contains exactly n alphabetic characters.

Parameters

NameTypeDescription
column_or_nameColumnThe column or string to be checked.
nintThe exact number of alphabetic characters to match.

Returns

ColumnColumn
A column of boolean values indicating whether each entry matches the regular expression.

is_n_numbers_onlyfunction#

def is_n_numbers_only(column_or_name: ColumnOrName, n: int | str) -> Column

Checks if the given column or string contains exactly n numeric characters.

Parameters

NameTypeDescription
column_or_nameColumnOrNameThe column or string to be checked.
nint | strThe exact number of numeric characters to match. or “+” for any length number.

Returns

ColumnColumn
A column of boolean values indicating whether each entry matches the regular expression.

is_printable_onlyfunction#

def is_printable_only(column_or_name: ColumnOrName) -> Column

Checks if the given column or string contains only printable characters.

Parameters

NameTypeDescription
column_or_nameColumnOrNameThe column or string to be checked.

Returns

ColumnColumn
A column of boolean values indicating whether each entry contains only printable characters.

is_two_character_onlyfunction#

def is_two_character_only(column_or_name: ColumnOrName) -> Column

Checks if the given column or string contains exactly two alphabetic characters (either lowercase or uppercase).

Parameters

NameTypeDescription
column_or_nameColumnOrNameThe column or string to be checked.

Returns

ColumnColumn
A boolean column indicating whether the input matches the pattern of exactly two alphabetic characters.

startswithsfunction#

def startswiths(column_or_name: ColumnOrName, list_of_strings: list[str]) -> pyspark.sql.Column

Creates a PySpark Column expression to check if the given column starts with any string in the list.

Parameters

NameTypeDescription
column_or_nameColumnOrNameThe column to check.
list_of_stringsList[str]A list of strings to check if the column starts with.

Returns

Columnpyspark.sql.Column
A PySpark Column expression that evaluates to True if the column starts with any string in the list, otherwise False.