# pysparky.functions.conditions

*module*

[View source](https://github.com/PySparky/pysparky-pyspark-helper/blob/327582f8b776fe7638082ce4b5be8153d3ce63d3/pysparky/functions/conditions.py#L1-L1)

## pysparky.functions.conditions.condition_and

*function*

```python
def condition_and(*conditions: ColumnOrName) -> Column
```

Combines multiple conditions using logical AND.

**Parameters**

- `*conditions` (`ColumnOrName`) (default: `()`) — Multiple PySpark Column objects or SQL expression strings representing conditions.

**Returns**

- `Column` (`Column`) — A single PySpark Column object representing the combined condition.

> **Example**
>
> ```python
> >>> condition_and(F.col('col1') > 1, F.col('col2') < 5)
> Column<'((col1 > 1) AND (col2 < 5))'>
> 
> >>> condition_and(F.col('col1') > 1, "col2 < 5")
> Column<'((col1 > 1) AND (col2 < 5))'>
> ```

[View source](https://github.com/PySparky/pysparky-pyspark-helper/blob/327582f8b776fe7638082ce4b5be8153d3ce63d3/pysparky/functions/conditions.py#L15-L37)

## pysparky.functions.conditions.condition_or

*function*

```python
def condition_or(*conditions: ColumnOrName) -> Column
```

Combines multiple conditions using logical OR.

**Parameters**

- `*conditions` (`ColumnOrName`) (default: `()`) — Multiple PySpark Column objects or SQL expression strings representing conditions.

**Returns**

- `Column` (`Column`) — A single PySpark Column object representing the combined condition.

> **Example**
>
> ```python
> >>> condition_or(F.col('col1') > 1, F.col('col2') < 5)
> Column<'((col1 > 1) OR (col2 < 5))'>
> 
> >>> condition_or(F.col('col1') > 1, "col2 < 5")
> Column<'((col1 > 1) OR (col2 < 5))'>
> ```

[View source](https://github.com/PySparky/pysparky-pyspark-helper/blob/327582f8b776fe7638082ce4b5be8153d3ce63d3/pysparky/functions/conditions.py#L40-L62)

## pysparky.functions.conditions.is_all_numbers_only

*function*

```python
def is_all_numbers_only(column_or_name) -> Column
```

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

**Parameters**

- `column_or_name` (`ColumnOrName`) — The column or string to be checked.

**Returns**

- `Column` (`Column`) — A column of boolean values indicating whether each entry contains only numeric characters.

> **Example**
>
> ```python
> >>> df = spark.createDataFrame([("123",), ("4567",), ("89a",), ("",), ("0",)], ["value"])
> >>> df.select(is_all_numbers_only(df["value"]).alias("is_all_numbers")).show()
> +--------------+
> |is_all_numbers|
> +--------------+
> |          true|
> |          true|
> |         false|
> |         false|
> |          true|
> +--------------+
> ```

[View source](https://github.com/PySparky/pysparky-pyspark-helper/blob/327582f8b776fe7638082ce4b5be8153d3ce63d3/pysparky/functions/conditions.py#L122-L147)

## pysparky.functions.conditions.is_array_monotonic

*function*

```python
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**

- `col` (`ColumnOrName`) — Array column to check.
- `cmp_fn` (`callable`) — Binary 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_policy` (`str`) (default: `'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**

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

> **Example**
>
> ```python
> >>> import operator as op
> >>> df = spark.createDataFrame([([1, 2, 3],), ([3, 2, 1],)], ["arr"])
> >>> df.select(is_array_monotonic(F.col("arr"), op.lt).alias("is_strictly_inc")).show()
> +---------------+
> |is_strictly_inc|
> +---------------+
> |           true|
> |          false|
> +---------------+
> ```

[View source](https://github.com/PySparky/pysparky-pyspark-helper/blob/327582f8b776fe7638082ce4b5be8153d3ce63d3/pysparky/functions/conditions.py#L255-L351)

## pysparky.functions.conditions.is_array_non_decreasing

*function*

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

Check if an array column is non-decreasing.

**Parameters**

- `col` (`ColumnOrName`) — Array column to check
- `null_policy` (`str`) (default: `'forbid'`) — How to treat NULL elements inside the array.

**Returns**

- `Column` (`Column`) — Boolean column: True if the array is non-decreasing, False otherwise.

> **Example**
>
> ```python
> >>> df = spark.createDataFrame([([1, 2, 2],), ([3, 2, 1],)], ["arr"])
> >>> df.select(is_array_non_decreasing(F.col("arr")).alias("is_non_dec")).show()
> +----------+
> |is_non_dec|
> +----------+
> |      true|
> |     false|
> +----------+
> ```

[View source](https://github.com/PySparky/pysparky-pyspark-helper/blob/327582f8b776fe7638082ce4b5be8153d3ce63d3/pysparky/functions/conditions.py#L380-L403)

## pysparky.functions.conditions.is_array_non_increasing

*function*

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

Check if an array column is non-increasing.

**Parameters**

- `col` (`ColumnOrName`) — Array column to check
- `null_policy` (`str`) (default: `'forbid'`) — How to treat NULL elements inside the array.

**Returns**

- `Column` (`Column`) — Boolean column: True if the array is non-increasing, False otherwise.

> **Example**
>
> ```python
> >>> df = spark.createDataFrame([([3, 2, 2],), ([1, 2, 3],)], ["arr"])
> >>> df.select(is_array_non_increasing(F.col("arr")).alias("is_non_inc")).show()
> +----------+
> |is_non_inc|
> +----------+
> |      true|
> |     false|
> +----------+
> ```

[View source](https://github.com/PySparky/pysparky-pyspark-helper/blob/327582f8b776fe7638082ce4b5be8153d3ce63d3/pysparky/functions/conditions.py#L432-L455)

## pysparky.functions.conditions.is_array_strictly_decreasing

*function*

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

Check if an array column is strictly decreasing.

**Parameters**

- `col` (`ColumnOrName`) — Array column to check
- `null_policy` (`str`) (default: `'forbid'`) — How to treat NULL elements inside the array.

**Returns**

- `Column` (`Column`) — Boolean column: True if the array is strictly decreasing, False otherwise.

> **Example**
>
> ```python
> >>> df = spark.createDataFrame([([3, 2, 1],), ([3, 2, 2],)], ["arr"])
> >>> df.select(is_array_strictly_decreasing(F.col("arr")).alias("is_dec")).show()
> +------+
> |is_dec|
> +------+
> |  true|
> | false|
> +------+
> ```

[View source](https://github.com/PySparky/pysparky-pyspark-helper/blob/327582f8b776fe7638082ce4b5be8153d3ce63d3/pysparky/functions/conditions.py#L406-L429)

## pysparky.functions.conditions.is_array_strictly_increasing

*function*

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

Check if an array column is strictly increasing.

**Parameters**

- `col` (`ColumnOrName`) — Array column to check
- `null_policy` (`str`) (default: `'forbid'`) — How to treat NULL elements inside the array.

**Returns**

- `Column` (`Column`) — Boolean column: True if the array is strictly increasing, False otherwise.

> **Example**
>
> ```python
> >>> df = spark.createDataFrame([([1, 2, 3],), ([1, 2, 2],)], ["arr"])
> >>> df.select(is_array_strictly_increasing(F.col("arr")).alias("is_inc")).show()
> +------+
> |is_inc|
> +------+
> |  true|
> | false|
> +------+
> ```

[View source](https://github.com/PySparky/pysparky-pyspark-helper/blob/327582f8b776fe7638082ce4b5be8153d3ce63d3/pysparky/functions/conditions.py#L354-L377)

## pysparky.functions.conditions.is_n_character_only

*function*

```python
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**

- `column_or_name` (`Column`) — The column or string to be checked.
- `n` (`int`) — The exact number of alphabetic characters to match.

**Returns**

- `Column` (`Column`) — A column of boolean values indicating whether each entry matches the regular expression.

> **Example**
>
> ```python
> >>> df = spark.createDataFrame([("a",), ("ab",), ("abc",), ("12",)], ["value"])
> >>> df.select(is_n_character_only(df["value"], 2).alias("is_two_char")).show()
> +-----------+
> |is_two_char|
> +-----------+
> |      false|
> |       true|
> |      false|
> |      false|
> +-----------+
> ```

[View source](https://github.com/PySparky/pysparky-pyspark-helper/blob/327582f8b776fe7638082ce4b5be8153d3ce63d3/pysparky/functions/conditions.py#L65-L92)

## pysparky.functions.conditions.is_n_numbers_only

*function*

```python
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**

- `column_or_name` (`ColumnOrName`) — The column or string to be checked.
- `n` (`int | str`) — The exact number of numeric characters to match. or "+" for any length number.

**Returns**

- `Column` (`Column`) — A column of boolean values indicating whether each entry matches the regular expression.

> **Example**
>
> ```python
> >>> df = spark.createDataFrame([("123",), ("4567",), ("89a",), ("",), ("0",)], ["value"])
> >>> df.select(is_n_numbers_only(df["value"], 3).alias("is_n_numbers")).show()
> +------------+
> |is_n_numbers|
> +------------+
> |        true|
> |       false|
> |       false|
> |       false|
> |       false|
> +------------+
> ```

[View source](https://github.com/PySparky/pysparky-pyspark-helper/blob/327582f8b776fe7638082ce4b5be8153d3ce63d3/pysparky/functions/conditions.py#L150-L186)

## pysparky.functions.conditions.is_printable_only

*function*

```python
def is_printable_only(column_or_name: ColumnOrName) -> Column
```

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

**Parameters**

- `column_or_name` (`ColumnOrName`) — The column or string to be checked.

**Returns**

- `Column` (`Column`) — A column of boolean values indicating whether each entry contains only printable characters.

> **Example**
>
> ```python
> >>> df = spark.createDataFrame([("Hello!",), ("World",), ("123",), ("",), ("Non-printable\x01",)], ["value"])
> >>> df.select(is_printable_only(df["value"]).alias("is_printable")).show()
> +------------+
> |is_printable|
> +------------+
> |        true|
> |        true|
> |        true|
> |       false|
> |       false|
> +------------+
> ```

[View source](https://github.com/PySparky/pysparky-pyspark-helper/blob/327582f8b776fe7638082ce4b5be8153d3ce63d3/pysparky/functions/conditions.py#L189-L216)

## pysparky.functions.conditions.is_two_character_only

*function*

```python
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**

- `column_or_name` (`ColumnOrName`) — The column or string to be checked.

**Returns**

- `Column` (`Column`) — A boolean column indicating whether the input matches the pattern of exactly two alphabetic characters.

> **Example**
>
> ```python
> >>> df = spark.createDataFrame([("aa",), ("ZZ",), ("a1",), ("abc",)], ["value"])
> >>> df.select(is_two_character_only(df["value"]).alias("is_two_char")).show()
> +-----------+
> |is_two_char|
> +-----------+
> |       true|
> |       true|
> |      false|
> |      false|
> +-----------+
> ```

[View source](https://github.com/PySparky/pysparky-pyspark-helper/blob/327582f8b776fe7638082ce4b5be8153d3ce63d3/pysparky/functions/conditions.py#L95-L119)

## pysparky.functions.conditions.startswiths

*function*

```python
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**

- `column_or_name` (`ColumnOrName`) — The column to check.
- `list_of_strings` (`List[str]`) — A list of strings to check if the column starts with.

**Returns**

- `Column` (`pyspark.sql.Column`) — A PySpark Column expression that evaluates to True if the column starts with any string in the list, otherwise False.

> **Example**
>
> ```python
> >>> df = spark.createDataFrame([("apple",), ("banana",), ("cherry",)], ["fruit"])
> >>> df.select("fruit", startswiths(F.col("fruit"), ["ap", "ch"]).alias("starts_with")).show()
> +------+-----------+
> | fruit|starts_with|
> +------+-----------+
> | apple|       true|
> |banana|      false|
> |cherry|       true|
> +------+-----------+
> ```

[View source](https://github.com/PySparky/pysparky-pyspark-helper/blob/327582f8b776fe7638082ce4b5be8153d3ce63d3/pysparky/functions/conditions.py#L219-L252)
