Skip to content

fenic.api.functions.core

Core functions for Fenic DataFrames.

Functions:

  • col

    Creates a Column expression referencing a column in the DataFrame.

  • lit

    Creates a Column expression representing a literal value.

col

col(col_name: str) -> Column

Creates a Column expression referencing a column in the DataFrame.

Parameters:

  • col_name (str) –

    Name of the column to reference

Returns:

  • Column

    A Column expression for the specified column

Raises:

  • TypeError

    If colName is not a string

Source code in src/fenic/api/functions/core.py
16
17
18
19
20
21
22
23
24
25
26
27
28
29
@validate_call(config=ConfigDict(strict=True))
def col(col_name: str) -> Column:
    """Creates a Column expression referencing a column in the DataFrame.

    Args:
        col_name: Name of the column to reference

    Returns:
        A Column expression for the specified column

    Raises:
        TypeError: If colName is not a string
    """
    return Column._from_column_name(col_name)

lit

lit(value: Any) -> Column

Creates a Column expression representing a literal value.

Parameters:

  • value (Any) –

    The literal value to create a column for

Returns:

  • Column

    A Column expression representing the literal value

Raises:

  • ValueError

    If the type of the value cannot be inferred

Source code in src/fenic/api/functions/core.py
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
def lit(value: Any) -> Column:
    """Creates a Column expression representing a literal value.

    Args:
        value: The literal value to create a column for

    Returns:
        A Column expression representing the literal value

    Raises:
        ValueError: If the type of the value cannot be inferred
    """
    try:
        inferred_type = infer_dtype_from_pyobj(value)
    except TypeInferenceError as e:
        raise ValidationError(f"`lit` failed to infer type for value `{value}`") from e
    literal_expr = LiteralExpr(value, inferred_type)
    return Column._from_logical_expr(literal_expr)