Skip to content

daft.functions.soundex#

soundex #

soundex(expr: Expression) -> Expression

Returns the Soundex code of the string.

Soundex is a phonetic algorithm that produces a 4-character code representing the sound of the string. This is compatible with Spark's soundex function.

Parameters:

Name Type Description Default
expr Expression

The string expression

required

Returns:

Name Type Description
Expression Expression

a String expression with the Soundex code

Examples:

1
2
3
4
5
>>> import daft
>>> from daft.functions import soundex
>>> df = daft.from_pydict({"x": ["Robert", "Rupert", "Smith"]})
>>> df = df.select(soundex(df["x"]))
>>> df.show()
╭────────╮
│ x      │
│ ---    │
│ String │
╞════════╡
│ R163   │
├╌╌╌╌╌╌╌╌┤
│ R163   │
├╌╌╌╌╌╌╌╌┤
│ S530   │
╰────────╯
(Showing first 3 of 3 rows)
Source code in daft/functions/str.py
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
def soundex(expr: Expression) -> Expression:
    """Returns the Soundex code of the string.

    Soundex is a phonetic algorithm that produces a 4-character code representing
    the sound of the string. This is compatible with Spark's soundex function.

    Args:
        expr: The string expression

    Returns:
        Expression: a String expression with the Soundex code

    Examples:
        >>> import daft
        >>> from daft.functions import soundex
        >>> df = daft.from_pydict({"x": ["Robert", "Rupert", "Smith"]})
        >>> df = df.select(soundex(df["x"]))
        >>> df.show()
        ╭────────╮
        │ x      │
        │ ---    │
        │ String │
        ╞════════╡
        │ R163   │
        ├╌╌╌╌╌╌╌╌┤
        │ R163   │
        ├╌╌╌╌╌╌╌╌┤
        │ S530   │
        ╰────────╯
        <BLANKLINE>
        (Showing first 3 of 3 rows)

    """
    return Expression._call_builtin_scalar_fn("soundex", expr)