Skip to content

Types

laktory.enums.DataFrameBackends ¤

Bases: str, Enum

METHOD DESCRIPTION
from_df

Instantiate DataFrameBackends object from a DataFrame.

from_nw_implementation

Instantiate DataFrameBackends object from a narwhals implementation.

ATTRIBUTE DESCRIPTION
POLARS

Polars backend.

PYSPARK

PySpark backend.

POLARS = auto() class-attribute instance-attribute ¤

Polars backend.

PYSPARK = auto() class-attribute instance-attribute ¤

PySpark backend.

from_df(df) classmethod ¤

Instantiate DataFrameBackends object from a DataFrame.

PARAMETER DESCRIPTION
df

DataFrame

TYPE: Any

RETURNS DESCRIPTION
output

DataFrameBackend

TYPE: DataFrameBackends

Source code in laktory/enums.py
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
@classmethod
def from_df(cls, df: Any) -> "DataFrameBackends":  # pragma: no cover
    """
    Instantiate DataFrameBackends object from a DataFrame.

    Parameters
    ----------
    df:
        DataFrame

    Returns
    -------
    output:
        DataFrameBackend
    """

    if not isinstance(df, (nw.DataFrame, nw.LazyFrame)):
        df = nw.from_native(df)

    return cls.from_nw_implementation(df.implementation)

from_nw_implementation(implementation) classmethod ¤

Instantiate DataFrameBackends object from a narwhals implementation.

PARAMETER DESCRIPTION
implementation

Narwhals implementation

TYPE: Implementation

RETURNS DESCRIPTION
output

DataFrameBackend

TYPE: DataFrameBackends

Source code in laktory/enums.py
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
@classmethod
def from_nw_implementation(
    cls, implementation: nw.Implementation
) -> "DataFrameBackends":  # pragma: no cover
    """
    Instantiate DataFrameBackends object from a narwhals implementation.

    Parameters
    ----------
    implementation:
        Narwhals implementation

    Returns
    -------
    output:
        DataFrameBackend
    """
    mapping = {
        nw.Implementation.PYSPARK: DataFrameBackends.PYSPARK,
        nw.Implementation.PYSPARK_CONNECT: DataFrameBackends.PYSPARK,
        nw.Implementation.POLARS: DataFrameBackends.POLARS,
        # get_modin(): Implementation.MODIN,
        # get_cudf(): Implementation.CUDF,
        # get_pyarrow(): Implementation.PYARROW,
        # get_pyspark_sql(): Implementation.PYSPARK,
        # get_polars(): Implementation.POLARS,
        # get_dask_dataframe(): Implementation.DASK,
        # get_duckdb(): Implementation.DUCKDB,
        # get_ibis(): Implementation.IBIS,
        # get_sqlframe(): Implementation.SQLFRAME,
    }

    if implementation not in mapping:
        raise ValueError(f"Implementation {implementation} is not supported.")

    return mapping.get(implementation)

laktory.typing.VariableType ¤

Bases: str

Laktory variable or expression (string)


laktory.typing.AnyFrame = nw.LazyFrame | nw.DataFrame module-attribute ¤