Skip to content

DataTypes

laktory.models.dtypes.DType ¤

Bases: BaseModel

Generic data type class.

Examples:

from laktory import models

# Int32
dtype = models.DType(name="Int32")
print(dtype)

# List of string
dtype = models.DType(name="list", inner="str")
print(dtype)

# Structure
dtype = models.DType(
    name="struct", fields={"x": {"name": "list", "inner": "double"}, "y": dtype}
)
print(dtype)
PARAMETER DESCRIPTION
category

Data type category

TYPE: Literal['NUMERIC', 'STRING', 'STRUCT'] | VariableType DEFAULT: 'NUMERIC'

fields

Definition of fields for Struct type.

TYPE: list[DField | VariableType] | VariableType DEFAULT: None

inner

Data type for sub-elements for Array or List types.

TYPE: str | DType | VariableType DEFAULT: None

name

Data type name.

TYPE: str | VariableType

shape

Definition of shape for Array type.

TYPE: int | list[int] | VariableType DEFAULT: None

METHOD DESCRIPTION
to_narwhals

Get equivalent Narwhals data type

to_polars

Get equivalent Polars data type

to_pyspark

Get equivalent Spark data type

to_narwhals() ¤

Get equivalent Narwhals data type

Source code in laktory/models/dtypes.py
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
def to_narwhals(self):
    """Get equivalent Narwhals data type"""
    nw_dtypes = nw.dtypes
    _type = self.name

    # Complex types
    if _type in "Array":
        return nw_dtypes.Array(inner=self.inner.to_narwhals(), shape=self.shape)

    if _type == "List":
        return nw_dtypes.List(inner=self.inner.to_narwhals())

    if _type == "Struct":
        fields = []
        for field in self.fields:
            fields += [nw.Field(name=field.name, dtype=field.dtype.to_narwhals())]
        return nw_dtypes.Struct(fields)

    if hasattr(nw_dtypes, _type):
        return getattr(nw_dtypes, _type)()

    # Not Found
    raise ValueError(f"Data type with name '{self.name}' is not supported")

to_polars() ¤

Get equivalent Polars data type

Source code in laktory/models/dtypes.py
240
241
242
243
244
245
246
247
def to_polars(self):
    """Get equivalent Polars data type"""
    from narwhals._polars.utils import narwhals_to_native_dtype

    return narwhals_to_native_dtype(
        dtype=self.to_narwhals(),
        version=nw._utils.Version.MAIN,
    )

to_pyspark() ¤

Get equivalent Spark data type

Source code in laktory/models/dtypes.py
225
226
227
228
229
230
231
232
233
234
235
236
237
238
def to_pyspark(self):
    """Get equivalent Spark data type"""
    import pyspark.sql.types as T
    from narwhals._spark_like.utils import narwhals_to_native_dtype

    from laktory import get_spark_session

    spark = get_spark_session()
    return narwhals_to_native_dtype(
        dtype=self.to_narwhals(),
        version=nw._utils.Version.MAIN,
        spark_types=T,
        session=spark,
    )

laktory.models.dtypes.DField ¤

Bases: BaseModel

Data Field definition

PARAMETER DESCRIPTION
dtype

Field data type

TYPE: str | DType | VariableType

name

Field name

TYPE: str | VariableType


laktory.models.dtypes.Array ¤

Bases: SpecificDType

PARAMETER DESCRIPTION
category

Data type category

TYPE: Literal['NUMERIC', 'STRING', 'STRUCT'] | VariableType DEFAULT: 'NUMERIC'

fields

Definition of fields for Struct type.

TYPE: list[DField | VariableType] | VariableType DEFAULT: None

inner

Data type for sub-elements for Array or List types.

TYPE: str | DType | VariableType

name

Data type name.

TYPE: str | VariableType DEFAULT: 'Array'

shape

Definition of shape for Array type.

TYPE: int | list[int] | VariableType

METHOD DESCRIPTION
set_name

Force dump of name property to allow de-serialization from DType model

to_narwhals

Get equivalent Narwhals data type

to_polars

Get equivalent Polars data type

to_pyspark

Get equivalent Spark data type

set_name() ¤

Force dump of name property to allow de-serialization from DType model

Source code in laktory/models/dtypes.py
254
255
256
257
258
@model_validator(mode="after")
def set_name(self) -> Any:
    """Force dump of `name` property to allow de-serialization from DType model"""
    self.model_fields_set.add("name")
    return self

to_narwhals() ¤

Get equivalent Narwhals data type

Source code in laktory/models/dtypes.py
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
def to_narwhals(self):
    """Get equivalent Narwhals data type"""
    nw_dtypes = nw.dtypes
    _type = self.name

    # Complex types
    if _type in "Array":
        return nw_dtypes.Array(inner=self.inner.to_narwhals(), shape=self.shape)

    if _type == "List":
        return nw_dtypes.List(inner=self.inner.to_narwhals())

    if _type == "Struct":
        fields = []
        for field in self.fields:
            fields += [nw.Field(name=field.name, dtype=field.dtype.to_narwhals())]
        return nw_dtypes.Struct(fields)

    if hasattr(nw_dtypes, _type):
        return getattr(nw_dtypes, _type)()

    # Not Found
    raise ValueError(f"Data type with name '{self.name}' is not supported")

to_polars() ¤

Get equivalent Polars data type

Source code in laktory/models/dtypes.py
240
241
242
243
244
245
246
247
def to_polars(self):
    """Get equivalent Polars data type"""
    from narwhals._polars.utils import narwhals_to_native_dtype

    return narwhals_to_native_dtype(
        dtype=self.to_narwhals(),
        version=nw._utils.Version.MAIN,
    )

to_pyspark() ¤

Get equivalent Spark data type

Source code in laktory/models/dtypes.py
225
226
227
228
229
230
231
232
233
234
235
236
237
238
def to_pyspark(self):
    """Get equivalent Spark data type"""
    import pyspark.sql.types as T
    from narwhals._spark_like.utils import narwhals_to_native_dtype

    from laktory import get_spark_session

    spark = get_spark_session()
    return narwhals_to_native_dtype(
        dtype=self.to_narwhals(),
        version=nw._utils.Version.MAIN,
        spark_types=T,
        session=spark,
    )

laktory.models.dtypes.List ¤

Bases: SpecificDType

PARAMETER DESCRIPTION
category

Data type category

TYPE: Literal['NUMERIC', 'STRING', 'STRUCT'] | VariableType DEFAULT: 'NUMERIC'

fields

Definition of fields for Struct type.

TYPE: list[DField | VariableType] | VariableType DEFAULT: None

inner

Data type for sub-elements for Array or List types.

TYPE: str | DType | VariableType

name

Data type name.

TYPE: str | VariableType DEFAULT: 'List'

shape

Definition of shape for Array type.

TYPE: int | list[int] | VariableType DEFAULT: None

METHOD DESCRIPTION
set_name

Force dump of name property to allow de-serialization from DType model

to_narwhals

Get equivalent Narwhals data type

to_polars

Get equivalent Polars data type

to_pyspark

Get equivalent Spark data type

set_name() ¤

Force dump of name property to allow de-serialization from DType model

Source code in laktory/models/dtypes.py
254
255
256
257
258
@model_validator(mode="after")
def set_name(self) -> Any:
    """Force dump of `name` property to allow de-serialization from DType model"""
    self.model_fields_set.add("name")
    return self

to_narwhals() ¤

Get equivalent Narwhals data type

Source code in laktory/models/dtypes.py
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
def to_narwhals(self):
    """Get equivalent Narwhals data type"""
    nw_dtypes = nw.dtypes
    _type = self.name

    # Complex types
    if _type in "Array":
        return nw_dtypes.Array(inner=self.inner.to_narwhals(), shape=self.shape)

    if _type == "List":
        return nw_dtypes.List(inner=self.inner.to_narwhals())

    if _type == "Struct":
        fields = []
        for field in self.fields:
            fields += [nw.Field(name=field.name, dtype=field.dtype.to_narwhals())]
        return nw_dtypes.Struct(fields)

    if hasattr(nw_dtypes, _type):
        return getattr(nw_dtypes, _type)()

    # Not Found
    raise ValueError(f"Data type with name '{self.name}' is not supported")

to_polars() ¤

Get equivalent Polars data type

Source code in laktory/models/dtypes.py
240
241
242
243
244
245
246
247
def to_polars(self):
    """Get equivalent Polars data type"""
    from narwhals._polars.utils import narwhals_to_native_dtype

    return narwhals_to_native_dtype(
        dtype=self.to_narwhals(),
        version=nw._utils.Version.MAIN,
    )

to_pyspark() ¤

Get equivalent Spark data type

Source code in laktory/models/dtypes.py
225
226
227
228
229
230
231
232
233
234
235
236
237
238
def to_pyspark(self):
    """Get equivalent Spark data type"""
    import pyspark.sql.types as T
    from narwhals._spark_like.utils import narwhals_to_native_dtype

    from laktory import get_spark_session

    spark = get_spark_session()
    return narwhals_to_native_dtype(
        dtype=self.to_narwhals(),
        version=nw._utils.Version.MAIN,
        spark_types=T,
        session=spark,
    )

laktory.models.dtypes.Struct ¤

Bases: SpecificDType

PARAMETER DESCRIPTION
category

Data type category

TYPE: Literal['NUMERIC', 'STRING', 'STRUCT'] | VariableType DEFAULT: 'NUMERIC'

fields

Definition of fields for Struct type.

TYPE: list[DField | VariableType] | VariableType

inner

Data type for sub-elements for Array or List types.

TYPE: str | DType | VariableType DEFAULT: None

name

Data type name.

TYPE: str | VariableType DEFAULT: 'Struct'

shape

Definition of shape for Array type.

TYPE: int | list[int] | VariableType DEFAULT: None

METHOD DESCRIPTION
set_name

Force dump of name property to allow de-serialization from DType model

to_narwhals

Get equivalent Narwhals data type

to_polars

Get equivalent Polars data type

to_pyspark

Get equivalent Spark data type

set_name() ¤

Force dump of name property to allow de-serialization from DType model

Source code in laktory/models/dtypes.py
254
255
256
257
258
@model_validator(mode="after")
def set_name(self) -> Any:
    """Force dump of `name` property to allow de-serialization from DType model"""
    self.model_fields_set.add("name")
    return self

to_narwhals() ¤

Get equivalent Narwhals data type

Source code in laktory/models/dtypes.py
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
def to_narwhals(self):
    """Get equivalent Narwhals data type"""
    nw_dtypes = nw.dtypes
    _type = self.name

    # Complex types
    if _type in "Array":
        return nw_dtypes.Array(inner=self.inner.to_narwhals(), shape=self.shape)

    if _type == "List":
        return nw_dtypes.List(inner=self.inner.to_narwhals())

    if _type == "Struct":
        fields = []
        for field in self.fields:
            fields += [nw.Field(name=field.name, dtype=field.dtype.to_narwhals())]
        return nw_dtypes.Struct(fields)

    if hasattr(nw_dtypes, _type):
        return getattr(nw_dtypes, _type)()

    # Not Found
    raise ValueError(f"Data type with name '{self.name}' is not supported")

to_polars() ¤

Get equivalent Polars data type

Source code in laktory/models/dtypes.py
240
241
242
243
244
245
246
247
def to_polars(self):
    """Get equivalent Polars data type"""
    from narwhals._polars.utils import narwhals_to_native_dtype

    return narwhals_to_native_dtype(
        dtype=self.to_narwhals(),
        version=nw._utils.Version.MAIN,
    )

to_pyspark() ¤

Get equivalent Spark data type

Source code in laktory/models/dtypes.py
225
226
227
228
229
230
231
232
233
234
235
236
237
238
def to_pyspark(self):
    """Get equivalent Spark data type"""
    import pyspark.sql.types as T
    from narwhals._spark_like.utils import narwhals_to_native_dtype

    from laktory import get_spark_session

    spark = get_spark_session()
    return narwhals_to_native_dtype(
        dtype=self.to_narwhals(),
        version=nw._utils.Version.MAIN,
        spark_types=T,
        session=spark,
    )

laktory.models.dtypes.Decimal ¤

Bases: SpecificDType

PARAMETER DESCRIPTION
category

Data type category

TYPE: Literal['NUMERIC', 'STRING', 'STRUCT'] | VariableType DEFAULT: 'NUMERIC'

fields

Definition of fields for Struct type.

TYPE: list[DField | VariableType] | VariableType DEFAULT: None

inner

Data type for sub-elements for Array or List types.

TYPE: str | DType | VariableType DEFAULT: None

name

Data type name.

TYPE: str | VariableType DEFAULT: 'Decimal'

shape

Definition of shape for Array type.

TYPE: int | list[int] | VariableType DEFAULT: None

METHOD DESCRIPTION
set_name

Force dump of name property to allow de-serialization from DType model

to_narwhals

Get equivalent Narwhals data type

to_polars

Get equivalent Polars data type

to_pyspark

Get equivalent Spark data type

set_name() ¤

Force dump of name property to allow de-serialization from DType model

Source code in laktory/models/dtypes.py
254
255
256
257
258
@model_validator(mode="after")
def set_name(self) -> Any:
    """Force dump of `name` property to allow de-serialization from DType model"""
    self.model_fields_set.add("name")
    return self

to_narwhals() ¤

Get equivalent Narwhals data type

Source code in laktory/models/dtypes.py
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
def to_narwhals(self):
    """Get equivalent Narwhals data type"""
    nw_dtypes = nw.dtypes
    _type = self.name

    # Complex types
    if _type in "Array":
        return nw_dtypes.Array(inner=self.inner.to_narwhals(), shape=self.shape)

    if _type == "List":
        return nw_dtypes.List(inner=self.inner.to_narwhals())

    if _type == "Struct":
        fields = []
        for field in self.fields:
            fields += [nw.Field(name=field.name, dtype=field.dtype.to_narwhals())]
        return nw_dtypes.Struct(fields)

    if hasattr(nw_dtypes, _type):
        return getattr(nw_dtypes, _type)()

    # Not Found
    raise ValueError(f"Data type with name '{self.name}' is not supported")

to_polars() ¤

Get equivalent Polars data type

Source code in laktory/models/dtypes.py
240
241
242
243
244
245
246
247
def to_polars(self):
    """Get equivalent Polars data type"""
    from narwhals._polars.utils import narwhals_to_native_dtype

    return narwhals_to_native_dtype(
        dtype=self.to_narwhals(),
        version=nw._utils.Version.MAIN,
    )

to_pyspark() ¤

Get equivalent Spark data type

Source code in laktory/models/dtypes.py
225
226
227
228
229
230
231
232
233
234
235
236
237
238
def to_pyspark(self):
    """Get equivalent Spark data type"""
    import pyspark.sql.types as T
    from narwhals._spark_like.utils import narwhals_to_native_dtype

    from laktory import get_spark_session

    spark = get_spark_session()
    return narwhals_to_native_dtype(
        dtype=self.to_narwhals(),
        version=nw._utils.Version.MAIN,
        spark_types=T,
        session=spark,
    )

laktory.models.dtypes.Int128 ¤

Bases: SpecificDType

PARAMETER DESCRIPTION
category

Data type category

TYPE: Literal['NUMERIC', 'STRING', 'STRUCT'] | VariableType DEFAULT: 'NUMERIC'

fields

Definition of fields for Struct type.

TYPE: list[DField | VariableType] | VariableType DEFAULT: None

inner

Data type for sub-elements for Array or List types.

TYPE: str | DType | VariableType DEFAULT: None

name

Data type name.

TYPE: str | VariableType DEFAULT: 'Int128'

shape

Definition of shape for Array type.

TYPE: int | list[int] | VariableType DEFAULT: None

METHOD DESCRIPTION
set_name

Force dump of name property to allow de-serialization from DType model

to_narwhals

Get equivalent Narwhals data type

to_polars

Get equivalent Polars data type

to_pyspark

Get equivalent Spark data type

set_name() ¤

Force dump of name property to allow de-serialization from DType model

Source code in laktory/models/dtypes.py
254
255
256
257
258
@model_validator(mode="after")
def set_name(self) -> Any:
    """Force dump of `name` property to allow de-serialization from DType model"""
    self.model_fields_set.add("name")
    return self

to_narwhals() ¤

Get equivalent Narwhals data type

Source code in laktory/models/dtypes.py
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
def to_narwhals(self):
    """Get equivalent Narwhals data type"""
    nw_dtypes = nw.dtypes
    _type = self.name

    # Complex types
    if _type in "Array":
        return nw_dtypes.Array(inner=self.inner.to_narwhals(), shape=self.shape)

    if _type == "List":
        return nw_dtypes.List(inner=self.inner.to_narwhals())

    if _type == "Struct":
        fields = []
        for field in self.fields:
            fields += [nw.Field(name=field.name, dtype=field.dtype.to_narwhals())]
        return nw_dtypes.Struct(fields)

    if hasattr(nw_dtypes, _type):
        return getattr(nw_dtypes, _type)()

    # Not Found
    raise ValueError(f"Data type with name '{self.name}' is not supported")

to_polars() ¤

Get equivalent Polars data type

Source code in laktory/models/dtypes.py
240
241
242
243
244
245
246
247
def to_polars(self):
    """Get equivalent Polars data type"""
    from narwhals._polars.utils import narwhals_to_native_dtype

    return narwhals_to_native_dtype(
        dtype=self.to_narwhals(),
        version=nw._utils.Version.MAIN,
    )

to_pyspark() ¤

Get equivalent Spark data type

Source code in laktory/models/dtypes.py
225
226
227
228
229
230
231
232
233
234
235
236
237
238
def to_pyspark(self):
    """Get equivalent Spark data type"""
    import pyspark.sql.types as T
    from narwhals._spark_like.utils import narwhals_to_native_dtype

    from laktory import get_spark_session

    spark = get_spark_session()
    return narwhals_to_native_dtype(
        dtype=self.to_narwhals(),
        version=nw._utils.Version.MAIN,
        spark_types=T,
        session=spark,
    )

laktory.models.dtypes.Int64 ¤

Bases: SpecificDType

PARAMETER DESCRIPTION
category

Data type category

TYPE: Literal['NUMERIC', 'STRING', 'STRUCT'] | VariableType DEFAULT: 'NUMERIC'

fields

Definition of fields for Struct type.

TYPE: list[DField | VariableType] | VariableType DEFAULT: None

inner

Data type for sub-elements for Array or List types.

TYPE: str | DType | VariableType DEFAULT: None

name

Data type name.

TYPE: str | VariableType DEFAULT: 'Int64'

shape

Definition of shape for Array type.

TYPE: int | list[int] | VariableType DEFAULT: None

METHOD DESCRIPTION
set_name

Force dump of name property to allow de-serialization from DType model

to_narwhals

Get equivalent Narwhals data type

to_polars

Get equivalent Polars data type

to_pyspark

Get equivalent Spark data type

set_name() ¤

Force dump of name property to allow de-serialization from DType model

Source code in laktory/models/dtypes.py
254
255
256
257
258
@model_validator(mode="after")
def set_name(self) -> Any:
    """Force dump of `name` property to allow de-serialization from DType model"""
    self.model_fields_set.add("name")
    return self

to_narwhals() ¤

Get equivalent Narwhals data type

Source code in laktory/models/dtypes.py
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
def to_narwhals(self):
    """Get equivalent Narwhals data type"""
    nw_dtypes = nw.dtypes
    _type = self.name

    # Complex types
    if _type in "Array":
        return nw_dtypes.Array(inner=self.inner.to_narwhals(), shape=self.shape)

    if _type == "List":
        return nw_dtypes.List(inner=self.inner.to_narwhals())

    if _type == "Struct":
        fields = []
        for field in self.fields:
            fields += [nw.Field(name=field.name, dtype=field.dtype.to_narwhals())]
        return nw_dtypes.Struct(fields)

    if hasattr(nw_dtypes, _type):
        return getattr(nw_dtypes, _type)()

    # Not Found
    raise ValueError(f"Data type with name '{self.name}' is not supported")

to_polars() ¤

Get equivalent Polars data type

Source code in laktory/models/dtypes.py
240
241
242
243
244
245
246
247
def to_polars(self):
    """Get equivalent Polars data type"""
    from narwhals._polars.utils import narwhals_to_native_dtype

    return narwhals_to_native_dtype(
        dtype=self.to_narwhals(),
        version=nw._utils.Version.MAIN,
    )

to_pyspark() ¤

Get equivalent Spark data type

Source code in laktory/models/dtypes.py
225
226
227
228
229
230
231
232
233
234
235
236
237
238
def to_pyspark(self):
    """Get equivalent Spark data type"""
    import pyspark.sql.types as T
    from narwhals._spark_like.utils import narwhals_to_native_dtype

    from laktory import get_spark_session

    spark = get_spark_session()
    return narwhals_to_native_dtype(
        dtype=self.to_narwhals(),
        version=nw._utils.Version.MAIN,
        spark_types=T,
        session=spark,
    )

laktory.models.dtypes.Int32 ¤

Bases: SpecificDType

PARAMETER DESCRIPTION
category

Data type category

TYPE: Literal['NUMERIC', 'STRING', 'STRUCT'] | VariableType DEFAULT: 'NUMERIC'

fields

Definition of fields for Struct type.

TYPE: list[DField | VariableType] | VariableType DEFAULT: None

inner

Data type for sub-elements for Array or List types.

TYPE: str | DType | VariableType DEFAULT: None

name

Data type name.

TYPE: str | VariableType DEFAULT: 'Int32'

shape

Definition of shape for Array type.

TYPE: int | list[int] | VariableType DEFAULT: None

METHOD DESCRIPTION
set_name

Force dump of name property to allow de-serialization from DType model

to_narwhals

Get equivalent Narwhals data type

to_polars

Get equivalent Polars data type

to_pyspark

Get equivalent Spark data type

set_name() ¤

Force dump of name property to allow de-serialization from DType model

Source code in laktory/models/dtypes.py
254
255
256
257
258
@model_validator(mode="after")
def set_name(self) -> Any:
    """Force dump of `name` property to allow de-serialization from DType model"""
    self.model_fields_set.add("name")
    return self

to_narwhals() ¤

Get equivalent Narwhals data type

Source code in laktory/models/dtypes.py
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
def to_narwhals(self):
    """Get equivalent Narwhals data type"""
    nw_dtypes = nw.dtypes
    _type = self.name

    # Complex types
    if _type in "Array":
        return nw_dtypes.Array(inner=self.inner.to_narwhals(), shape=self.shape)

    if _type == "List":
        return nw_dtypes.List(inner=self.inner.to_narwhals())

    if _type == "Struct":
        fields = []
        for field in self.fields:
            fields += [nw.Field(name=field.name, dtype=field.dtype.to_narwhals())]
        return nw_dtypes.Struct(fields)

    if hasattr(nw_dtypes, _type):
        return getattr(nw_dtypes, _type)()

    # Not Found
    raise ValueError(f"Data type with name '{self.name}' is not supported")

to_polars() ¤

Get equivalent Polars data type

Source code in laktory/models/dtypes.py
240
241
242
243
244
245
246
247
def to_polars(self):
    """Get equivalent Polars data type"""
    from narwhals._polars.utils import narwhals_to_native_dtype

    return narwhals_to_native_dtype(
        dtype=self.to_narwhals(),
        version=nw._utils.Version.MAIN,
    )

to_pyspark() ¤

Get equivalent Spark data type

Source code in laktory/models/dtypes.py
225
226
227
228
229
230
231
232
233
234
235
236
237
238
def to_pyspark(self):
    """Get equivalent Spark data type"""
    import pyspark.sql.types as T
    from narwhals._spark_like.utils import narwhals_to_native_dtype

    from laktory import get_spark_session

    spark = get_spark_session()
    return narwhals_to_native_dtype(
        dtype=self.to_narwhals(),
        version=nw._utils.Version.MAIN,
        spark_types=T,
        session=spark,
    )

laktory.models.dtypes.Int16 ¤

Bases: SpecificDType

PARAMETER DESCRIPTION
category

Data type category

TYPE: Literal['NUMERIC', 'STRING', 'STRUCT'] | VariableType DEFAULT: 'NUMERIC'

fields

Definition of fields for Struct type.

TYPE: list[DField | VariableType] | VariableType DEFAULT: None

inner

Data type for sub-elements for Array or List types.

TYPE: str | DType | VariableType DEFAULT: None

name

Data type name.

TYPE: str | VariableType DEFAULT: 'Int16'

shape

Definition of shape for Array type.

TYPE: int | list[int] | VariableType DEFAULT: None

METHOD DESCRIPTION
set_name

Force dump of name property to allow de-serialization from DType model

to_narwhals

Get equivalent Narwhals data type

to_polars

Get equivalent Polars data type

to_pyspark

Get equivalent Spark data type

set_name() ¤

Force dump of name property to allow de-serialization from DType model

Source code in laktory/models/dtypes.py
254
255
256
257
258
@model_validator(mode="after")
def set_name(self) -> Any:
    """Force dump of `name` property to allow de-serialization from DType model"""
    self.model_fields_set.add("name")
    return self

to_narwhals() ¤

Get equivalent Narwhals data type

Source code in laktory/models/dtypes.py
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
def to_narwhals(self):
    """Get equivalent Narwhals data type"""
    nw_dtypes = nw.dtypes
    _type = self.name

    # Complex types
    if _type in "Array":
        return nw_dtypes.Array(inner=self.inner.to_narwhals(), shape=self.shape)

    if _type == "List":
        return nw_dtypes.List(inner=self.inner.to_narwhals())

    if _type == "Struct":
        fields = []
        for field in self.fields:
            fields += [nw.Field(name=field.name, dtype=field.dtype.to_narwhals())]
        return nw_dtypes.Struct(fields)

    if hasattr(nw_dtypes, _type):
        return getattr(nw_dtypes, _type)()

    # Not Found
    raise ValueError(f"Data type with name '{self.name}' is not supported")

to_polars() ¤

Get equivalent Polars data type

Source code in laktory/models/dtypes.py
240
241
242
243
244
245
246
247
def to_polars(self):
    """Get equivalent Polars data type"""
    from narwhals._polars.utils import narwhals_to_native_dtype

    return narwhals_to_native_dtype(
        dtype=self.to_narwhals(),
        version=nw._utils.Version.MAIN,
    )

to_pyspark() ¤

Get equivalent Spark data type

Source code in laktory/models/dtypes.py
225
226
227
228
229
230
231
232
233
234
235
236
237
238
def to_pyspark(self):
    """Get equivalent Spark data type"""
    import pyspark.sql.types as T
    from narwhals._spark_like.utils import narwhals_to_native_dtype

    from laktory import get_spark_session

    spark = get_spark_session()
    return narwhals_to_native_dtype(
        dtype=self.to_narwhals(),
        version=nw._utils.Version.MAIN,
        spark_types=T,
        session=spark,
    )

laktory.models.dtypes.Int8 ¤

Bases: SpecificDType

PARAMETER DESCRIPTION
category

Data type category

TYPE: Literal['NUMERIC', 'STRING', 'STRUCT'] | VariableType DEFAULT: 'NUMERIC'

fields

Definition of fields for Struct type.

TYPE: list[DField | VariableType] | VariableType DEFAULT: None

inner

Data type for sub-elements for Array or List types.

TYPE: str | DType | VariableType DEFAULT: None

name

Data type name.

TYPE: str | VariableType DEFAULT: 'Int8'

shape

Definition of shape for Array type.

TYPE: int | list[int] | VariableType DEFAULT: None

METHOD DESCRIPTION
set_name

Force dump of name property to allow de-serialization from DType model

to_narwhals

Get equivalent Narwhals data type

to_polars

Get equivalent Polars data type

to_pyspark

Get equivalent Spark data type

set_name() ¤

Force dump of name property to allow de-serialization from DType model

Source code in laktory/models/dtypes.py
254
255
256
257
258
@model_validator(mode="after")
def set_name(self) -> Any:
    """Force dump of `name` property to allow de-serialization from DType model"""
    self.model_fields_set.add("name")
    return self

to_narwhals() ¤

Get equivalent Narwhals data type

Source code in laktory/models/dtypes.py
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
def to_narwhals(self):
    """Get equivalent Narwhals data type"""
    nw_dtypes = nw.dtypes
    _type = self.name

    # Complex types
    if _type in "Array":
        return nw_dtypes.Array(inner=self.inner.to_narwhals(), shape=self.shape)

    if _type == "List":
        return nw_dtypes.List(inner=self.inner.to_narwhals())

    if _type == "Struct":
        fields = []
        for field in self.fields:
            fields += [nw.Field(name=field.name, dtype=field.dtype.to_narwhals())]
        return nw_dtypes.Struct(fields)

    if hasattr(nw_dtypes, _type):
        return getattr(nw_dtypes, _type)()

    # Not Found
    raise ValueError(f"Data type with name '{self.name}' is not supported")

to_polars() ¤

Get equivalent Polars data type

Source code in laktory/models/dtypes.py
240
241
242
243
244
245
246
247
def to_polars(self):
    """Get equivalent Polars data type"""
    from narwhals._polars.utils import narwhals_to_native_dtype

    return narwhals_to_native_dtype(
        dtype=self.to_narwhals(),
        version=nw._utils.Version.MAIN,
    )

to_pyspark() ¤

Get equivalent Spark data type

Source code in laktory/models/dtypes.py
225
226
227
228
229
230
231
232
233
234
235
236
237
238
def to_pyspark(self):
    """Get equivalent Spark data type"""
    import pyspark.sql.types as T
    from narwhals._spark_like.utils import narwhals_to_native_dtype

    from laktory import get_spark_session

    spark = get_spark_session()
    return narwhals_to_native_dtype(
        dtype=self.to_narwhals(),
        version=nw._utils.Version.MAIN,
        spark_types=T,
        session=spark,
    )

laktory.models.dtypes.UInt128 ¤

Bases: SpecificDType

PARAMETER DESCRIPTION
category

Data type category

TYPE: Literal['NUMERIC', 'STRING', 'STRUCT'] | VariableType DEFAULT: 'NUMERIC'

fields

Definition of fields for Struct type.

TYPE: list[DField | VariableType] | VariableType DEFAULT: None

inner

Data type for sub-elements for Array or List types.

TYPE: str | DType | VariableType DEFAULT: None

name

Data type name.

TYPE: str | VariableType DEFAULT: 'UInt128'

shape

Definition of shape for Array type.

TYPE: int | list[int] | VariableType DEFAULT: None

METHOD DESCRIPTION
set_name

Force dump of name property to allow de-serialization from DType model

to_narwhals

Get equivalent Narwhals data type

to_polars

Get equivalent Polars data type

to_pyspark

Get equivalent Spark data type

set_name() ¤

Force dump of name property to allow de-serialization from DType model

Source code in laktory/models/dtypes.py
254
255
256
257
258
@model_validator(mode="after")
def set_name(self) -> Any:
    """Force dump of `name` property to allow de-serialization from DType model"""
    self.model_fields_set.add("name")
    return self

to_narwhals() ¤

Get equivalent Narwhals data type

Source code in laktory/models/dtypes.py
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
def to_narwhals(self):
    """Get equivalent Narwhals data type"""
    nw_dtypes = nw.dtypes
    _type = self.name

    # Complex types
    if _type in "Array":
        return nw_dtypes.Array(inner=self.inner.to_narwhals(), shape=self.shape)

    if _type == "List":
        return nw_dtypes.List(inner=self.inner.to_narwhals())

    if _type == "Struct":
        fields = []
        for field in self.fields:
            fields += [nw.Field(name=field.name, dtype=field.dtype.to_narwhals())]
        return nw_dtypes.Struct(fields)

    if hasattr(nw_dtypes, _type):
        return getattr(nw_dtypes, _type)()

    # Not Found
    raise ValueError(f"Data type with name '{self.name}' is not supported")

to_polars() ¤

Get equivalent Polars data type

Source code in laktory/models/dtypes.py
240
241
242
243
244
245
246
247
def to_polars(self):
    """Get equivalent Polars data type"""
    from narwhals._polars.utils import narwhals_to_native_dtype

    return narwhals_to_native_dtype(
        dtype=self.to_narwhals(),
        version=nw._utils.Version.MAIN,
    )

to_pyspark() ¤

Get equivalent Spark data type

Source code in laktory/models/dtypes.py
225
226
227
228
229
230
231
232
233
234
235
236
237
238
def to_pyspark(self):
    """Get equivalent Spark data type"""
    import pyspark.sql.types as T
    from narwhals._spark_like.utils import narwhals_to_native_dtype

    from laktory import get_spark_session

    spark = get_spark_session()
    return narwhals_to_native_dtype(
        dtype=self.to_narwhals(),
        version=nw._utils.Version.MAIN,
        spark_types=T,
        session=spark,
    )

laktory.models.dtypes.UInt64 ¤

Bases: SpecificDType

PARAMETER DESCRIPTION
category

Data type category

TYPE: Literal['NUMERIC', 'STRING', 'STRUCT'] | VariableType DEFAULT: 'NUMERIC'

fields

Definition of fields for Struct type.

TYPE: list[DField | VariableType] | VariableType DEFAULT: None

inner

Data type for sub-elements for Array or List types.

TYPE: str | DType | VariableType DEFAULT: None

name

Data type name.

TYPE: str | VariableType DEFAULT: 'UInt64'

shape

Definition of shape for Array type.

TYPE: int | list[int] | VariableType DEFAULT: None

METHOD DESCRIPTION
set_name

Force dump of name property to allow de-serialization from DType model

to_narwhals

Get equivalent Narwhals data type

to_polars

Get equivalent Polars data type

to_pyspark

Get equivalent Spark data type

set_name() ¤

Force dump of name property to allow de-serialization from DType model

Source code in laktory/models/dtypes.py
254
255
256
257
258
@model_validator(mode="after")
def set_name(self) -> Any:
    """Force dump of `name` property to allow de-serialization from DType model"""
    self.model_fields_set.add("name")
    return self

to_narwhals() ¤

Get equivalent Narwhals data type

Source code in laktory/models/dtypes.py
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
def to_narwhals(self):
    """Get equivalent Narwhals data type"""
    nw_dtypes = nw.dtypes
    _type = self.name

    # Complex types
    if _type in "Array":
        return nw_dtypes.Array(inner=self.inner.to_narwhals(), shape=self.shape)

    if _type == "List":
        return nw_dtypes.List(inner=self.inner.to_narwhals())

    if _type == "Struct":
        fields = []
        for field in self.fields:
            fields += [nw.Field(name=field.name, dtype=field.dtype.to_narwhals())]
        return nw_dtypes.Struct(fields)

    if hasattr(nw_dtypes, _type):
        return getattr(nw_dtypes, _type)()

    # Not Found
    raise ValueError(f"Data type with name '{self.name}' is not supported")

to_polars() ¤

Get equivalent Polars data type

Source code in laktory/models/dtypes.py
240
241
242
243
244
245
246
247
def to_polars(self):
    """Get equivalent Polars data type"""
    from narwhals._polars.utils import narwhals_to_native_dtype

    return narwhals_to_native_dtype(
        dtype=self.to_narwhals(),
        version=nw._utils.Version.MAIN,
    )

to_pyspark() ¤

Get equivalent Spark data type

Source code in laktory/models/dtypes.py
225
226
227
228
229
230
231
232
233
234
235
236
237
238
def to_pyspark(self):
    """Get equivalent Spark data type"""
    import pyspark.sql.types as T
    from narwhals._spark_like.utils import narwhals_to_native_dtype

    from laktory import get_spark_session

    spark = get_spark_session()
    return narwhals_to_native_dtype(
        dtype=self.to_narwhals(),
        version=nw._utils.Version.MAIN,
        spark_types=T,
        session=spark,
    )

laktory.models.dtypes.UInt32 ¤

Bases: SpecificDType

PARAMETER DESCRIPTION
category

Data type category

TYPE: Literal['NUMERIC', 'STRING', 'STRUCT'] | VariableType DEFAULT: 'NUMERIC'

fields

Definition of fields for Struct type.

TYPE: list[DField | VariableType] | VariableType DEFAULT: None

inner

Data type for sub-elements for Array or List types.

TYPE: str | DType | VariableType DEFAULT: None

name

Data type name.

TYPE: str | VariableType DEFAULT: 'UInt32'

shape

Definition of shape for Array type.

TYPE: int | list[int] | VariableType DEFAULT: None

METHOD DESCRIPTION
set_name

Force dump of name property to allow de-serialization from DType model

to_narwhals

Get equivalent Narwhals data type

to_polars

Get equivalent Polars data type

to_pyspark

Get equivalent Spark data type

set_name() ¤

Force dump of name property to allow de-serialization from DType model

Source code in laktory/models/dtypes.py
254
255
256
257
258
@model_validator(mode="after")
def set_name(self) -> Any:
    """Force dump of `name` property to allow de-serialization from DType model"""
    self.model_fields_set.add("name")
    return self

to_narwhals() ¤

Get equivalent Narwhals data type

Source code in laktory/models/dtypes.py
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
def to_narwhals(self):
    """Get equivalent Narwhals data type"""
    nw_dtypes = nw.dtypes
    _type = self.name

    # Complex types
    if _type in "Array":
        return nw_dtypes.Array(inner=self.inner.to_narwhals(), shape=self.shape)

    if _type == "List":
        return nw_dtypes.List(inner=self.inner.to_narwhals())

    if _type == "Struct":
        fields = []
        for field in self.fields:
            fields += [nw.Field(name=field.name, dtype=field.dtype.to_narwhals())]
        return nw_dtypes.Struct(fields)

    if hasattr(nw_dtypes, _type):
        return getattr(nw_dtypes, _type)()

    # Not Found
    raise ValueError(f"Data type with name '{self.name}' is not supported")

to_polars() ¤

Get equivalent Polars data type

Source code in laktory/models/dtypes.py
240
241
242
243
244
245
246
247
def to_polars(self):
    """Get equivalent Polars data type"""
    from narwhals._polars.utils import narwhals_to_native_dtype

    return narwhals_to_native_dtype(
        dtype=self.to_narwhals(),
        version=nw._utils.Version.MAIN,
    )

to_pyspark() ¤

Get equivalent Spark data type

Source code in laktory/models/dtypes.py
225
226
227
228
229
230
231
232
233
234
235
236
237
238
def to_pyspark(self):
    """Get equivalent Spark data type"""
    import pyspark.sql.types as T
    from narwhals._spark_like.utils import narwhals_to_native_dtype

    from laktory import get_spark_session

    spark = get_spark_session()
    return narwhals_to_native_dtype(
        dtype=self.to_narwhals(),
        version=nw._utils.Version.MAIN,
        spark_types=T,
        session=spark,
    )

laktory.models.dtypes.UInt16 ¤

Bases: SpecificDType

PARAMETER DESCRIPTION
category

Data type category

TYPE: Literal['NUMERIC', 'STRING', 'STRUCT'] | VariableType DEFAULT: 'NUMERIC'

fields

Definition of fields for Struct type.

TYPE: list[DField | VariableType] | VariableType DEFAULT: None

inner

Data type for sub-elements for Array or List types.

TYPE: str | DType | VariableType DEFAULT: None

name

Data type name.

TYPE: str | VariableType DEFAULT: 'UInt16'

shape

Definition of shape for Array type.

TYPE: int | list[int] | VariableType DEFAULT: None

METHOD DESCRIPTION
set_name

Force dump of name property to allow de-serialization from DType model

to_narwhals

Get equivalent Narwhals data type

to_polars

Get equivalent Polars data type

to_pyspark

Get equivalent Spark data type

set_name() ¤

Force dump of name property to allow de-serialization from DType model

Source code in laktory/models/dtypes.py
254
255
256
257
258
@model_validator(mode="after")
def set_name(self) -> Any:
    """Force dump of `name` property to allow de-serialization from DType model"""
    self.model_fields_set.add("name")
    return self

to_narwhals() ¤

Get equivalent Narwhals data type

Source code in laktory/models/dtypes.py
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
def to_narwhals(self):
    """Get equivalent Narwhals data type"""
    nw_dtypes = nw.dtypes
    _type = self.name

    # Complex types
    if _type in "Array":
        return nw_dtypes.Array(inner=self.inner.to_narwhals(), shape=self.shape)

    if _type == "List":
        return nw_dtypes.List(inner=self.inner.to_narwhals())

    if _type == "Struct":
        fields = []
        for field in self.fields:
            fields += [nw.Field(name=field.name, dtype=field.dtype.to_narwhals())]
        return nw_dtypes.Struct(fields)

    if hasattr(nw_dtypes, _type):
        return getattr(nw_dtypes, _type)()

    # Not Found
    raise ValueError(f"Data type with name '{self.name}' is not supported")

to_polars() ¤

Get equivalent Polars data type

Source code in laktory/models/dtypes.py
240
241
242
243
244
245
246
247
def to_polars(self):
    """Get equivalent Polars data type"""
    from narwhals._polars.utils import narwhals_to_native_dtype

    return narwhals_to_native_dtype(
        dtype=self.to_narwhals(),
        version=nw._utils.Version.MAIN,
    )

to_pyspark() ¤

Get equivalent Spark data type

Source code in laktory/models/dtypes.py
225
226
227
228
229
230
231
232
233
234
235
236
237
238
def to_pyspark(self):
    """Get equivalent Spark data type"""
    import pyspark.sql.types as T
    from narwhals._spark_like.utils import narwhals_to_native_dtype

    from laktory import get_spark_session

    spark = get_spark_session()
    return narwhals_to_native_dtype(
        dtype=self.to_narwhals(),
        version=nw._utils.Version.MAIN,
        spark_types=T,
        session=spark,
    )

laktory.models.dtypes.UInt8 ¤

Bases: SpecificDType

PARAMETER DESCRIPTION
category

Data type category

TYPE: Literal['NUMERIC', 'STRING', 'STRUCT'] | VariableType DEFAULT: 'NUMERIC'

fields

Definition of fields for Struct type.

TYPE: list[DField | VariableType] | VariableType DEFAULT: None

inner

Data type for sub-elements for Array or List types.

TYPE: str | DType | VariableType DEFAULT: None

name

Data type name.

TYPE: str | VariableType DEFAULT: 'UInt8'

shape

Definition of shape for Array type.

TYPE: int | list[int] | VariableType DEFAULT: None

METHOD DESCRIPTION
set_name

Force dump of name property to allow de-serialization from DType model

to_narwhals

Get equivalent Narwhals data type

to_polars

Get equivalent Polars data type

to_pyspark

Get equivalent Spark data type

set_name() ¤

Force dump of name property to allow de-serialization from DType model

Source code in laktory/models/dtypes.py
254
255
256
257
258
@model_validator(mode="after")
def set_name(self) -> Any:
    """Force dump of `name` property to allow de-serialization from DType model"""
    self.model_fields_set.add("name")
    return self

to_narwhals() ¤

Get equivalent Narwhals data type

Source code in laktory/models/dtypes.py
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
def to_narwhals(self):
    """Get equivalent Narwhals data type"""
    nw_dtypes = nw.dtypes
    _type = self.name

    # Complex types
    if _type in "Array":
        return nw_dtypes.Array(inner=self.inner.to_narwhals(), shape=self.shape)

    if _type == "List":
        return nw_dtypes.List(inner=self.inner.to_narwhals())

    if _type == "Struct":
        fields = []
        for field in self.fields:
            fields += [nw.Field(name=field.name, dtype=field.dtype.to_narwhals())]
        return nw_dtypes.Struct(fields)

    if hasattr(nw_dtypes, _type):
        return getattr(nw_dtypes, _type)()

    # Not Found
    raise ValueError(f"Data type with name '{self.name}' is not supported")

to_polars() ¤

Get equivalent Polars data type

Source code in laktory/models/dtypes.py
240
241
242
243
244
245
246
247
def to_polars(self):
    """Get equivalent Polars data type"""
    from narwhals._polars.utils import narwhals_to_native_dtype

    return narwhals_to_native_dtype(
        dtype=self.to_narwhals(),
        version=nw._utils.Version.MAIN,
    )

to_pyspark() ¤

Get equivalent Spark data type

Source code in laktory/models/dtypes.py
225
226
227
228
229
230
231
232
233
234
235
236
237
238
def to_pyspark(self):
    """Get equivalent Spark data type"""
    import pyspark.sql.types as T
    from narwhals._spark_like.utils import narwhals_to_native_dtype

    from laktory import get_spark_session

    spark = get_spark_session()
    return narwhals_to_native_dtype(
        dtype=self.to_narwhals(),
        version=nw._utils.Version.MAIN,
        spark_types=T,
        session=spark,
    )

laktory.models.dtypes.Float32 ¤

Bases: SpecificDType

PARAMETER DESCRIPTION
category

Data type category

TYPE: Literal['NUMERIC', 'STRING', 'STRUCT'] | VariableType DEFAULT: 'NUMERIC'

fields

Definition of fields for Struct type.

TYPE: list[DField | VariableType] | VariableType DEFAULT: None

inner

Data type for sub-elements for Array or List types.

TYPE: str | DType | VariableType DEFAULT: None

name

Data type name.

TYPE: str | VariableType DEFAULT: 'Float32'

shape

Definition of shape for Array type.

TYPE: int | list[int] | VariableType DEFAULT: None

METHOD DESCRIPTION
set_name

Force dump of name property to allow de-serialization from DType model

to_narwhals

Get equivalent Narwhals data type

to_polars

Get equivalent Polars data type

to_pyspark

Get equivalent Spark data type

set_name() ¤

Force dump of name property to allow de-serialization from DType model

Source code in laktory/models/dtypes.py
254
255
256
257
258
@model_validator(mode="after")
def set_name(self) -> Any:
    """Force dump of `name` property to allow de-serialization from DType model"""
    self.model_fields_set.add("name")
    return self

to_narwhals() ¤

Get equivalent Narwhals data type

Source code in laktory/models/dtypes.py
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
def to_narwhals(self):
    """Get equivalent Narwhals data type"""
    nw_dtypes = nw.dtypes
    _type = self.name

    # Complex types
    if _type in "Array":
        return nw_dtypes.Array(inner=self.inner.to_narwhals(), shape=self.shape)

    if _type == "List":
        return nw_dtypes.List(inner=self.inner.to_narwhals())

    if _type == "Struct":
        fields = []
        for field in self.fields:
            fields += [nw.Field(name=field.name, dtype=field.dtype.to_narwhals())]
        return nw_dtypes.Struct(fields)

    if hasattr(nw_dtypes, _type):
        return getattr(nw_dtypes, _type)()

    # Not Found
    raise ValueError(f"Data type with name '{self.name}' is not supported")

to_polars() ¤

Get equivalent Polars data type

Source code in laktory/models/dtypes.py
240
241
242
243
244
245
246
247
def to_polars(self):
    """Get equivalent Polars data type"""
    from narwhals._polars.utils import narwhals_to_native_dtype

    return narwhals_to_native_dtype(
        dtype=self.to_narwhals(),
        version=nw._utils.Version.MAIN,
    )

to_pyspark() ¤

Get equivalent Spark data type

Source code in laktory/models/dtypes.py
225
226
227
228
229
230
231
232
233
234
235
236
237
238
def to_pyspark(self):
    """Get equivalent Spark data type"""
    import pyspark.sql.types as T
    from narwhals._spark_like.utils import narwhals_to_native_dtype

    from laktory import get_spark_session

    spark = get_spark_session()
    return narwhals_to_native_dtype(
        dtype=self.to_narwhals(),
        version=nw._utils.Version.MAIN,
        spark_types=T,
        session=spark,
    )

laktory.models.dtypes.Float64 ¤

Bases: SpecificDType

PARAMETER DESCRIPTION
category

Data type category

TYPE: Literal['NUMERIC', 'STRING', 'STRUCT'] | VariableType DEFAULT: 'NUMERIC'

fields

Definition of fields for Struct type.

TYPE: list[DField | VariableType] | VariableType DEFAULT: None

inner

Data type for sub-elements for Array or List types.

TYPE: str | DType | VariableType DEFAULT: None

name

Data type name.

TYPE: str | VariableType DEFAULT: 'Float64'

shape

Definition of shape for Array type.

TYPE: int | list[int] | VariableType DEFAULT: None

METHOD DESCRIPTION
set_name

Force dump of name property to allow de-serialization from DType model

to_narwhals

Get equivalent Narwhals data type

to_polars

Get equivalent Polars data type

to_pyspark

Get equivalent Spark data type

set_name() ¤

Force dump of name property to allow de-serialization from DType model

Source code in laktory/models/dtypes.py
254
255
256
257
258
@model_validator(mode="after")
def set_name(self) -> Any:
    """Force dump of `name` property to allow de-serialization from DType model"""
    self.model_fields_set.add("name")
    return self

to_narwhals() ¤

Get equivalent Narwhals data type

Source code in laktory/models/dtypes.py
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
def to_narwhals(self):
    """Get equivalent Narwhals data type"""
    nw_dtypes = nw.dtypes
    _type = self.name

    # Complex types
    if _type in "Array":
        return nw_dtypes.Array(inner=self.inner.to_narwhals(), shape=self.shape)

    if _type == "List":
        return nw_dtypes.List(inner=self.inner.to_narwhals())

    if _type == "Struct":
        fields = []
        for field in self.fields:
            fields += [nw.Field(name=field.name, dtype=field.dtype.to_narwhals())]
        return nw_dtypes.Struct(fields)

    if hasattr(nw_dtypes, _type):
        return getattr(nw_dtypes, _type)()

    # Not Found
    raise ValueError(f"Data type with name '{self.name}' is not supported")

to_polars() ¤

Get equivalent Polars data type

Source code in laktory/models/dtypes.py
240
241
242
243
244
245
246
247
def to_polars(self):
    """Get equivalent Polars data type"""
    from narwhals._polars.utils import narwhals_to_native_dtype

    return narwhals_to_native_dtype(
        dtype=self.to_narwhals(),
        version=nw._utils.Version.MAIN,
    )

to_pyspark() ¤

Get equivalent Spark data type

Source code in laktory/models/dtypes.py
225
226
227
228
229
230
231
232
233
234
235
236
237
238
def to_pyspark(self):
    """Get equivalent Spark data type"""
    import pyspark.sql.types as T
    from narwhals._spark_like.utils import narwhals_to_native_dtype

    from laktory import get_spark_session

    spark = get_spark_session()
    return narwhals_to_native_dtype(
        dtype=self.to_narwhals(),
        version=nw._utils.Version.MAIN,
        spark_types=T,
        session=spark,
    )

laktory.models.dtypes.String ¤

Bases: SpecificDType

PARAMETER DESCRIPTION
category

Data type category

TYPE: Literal['NUMERIC', 'STRING', 'STRUCT'] | VariableType DEFAULT: 'NUMERIC'

fields

Definition of fields for Struct type.

TYPE: list[DField | VariableType] | VariableType DEFAULT: None

inner

Data type for sub-elements for Array or List types.

TYPE: str | DType | VariableType DEFAULT: None

name

Data type name.

TYPE: str | VariableType DEFAULT: 'String'

shape

Definition of shape for Array type.

TYPE: int | list[int] | VariableType DEFAULT: None

METHOD DESCRIPTION
set_name

Force dump of name property to allow de-serialization from DType model

to_narwhals

Get equivalent Narwhals data type

to_polars

Get equivalent Polars data type

to_pyspark

Get equivalent Spark data type

set_name() ¤

Force dump of name property to allow de-serialization from DType model

Source code in laktory/models/dtypes.py
254
255
256
257
258
@model_validator(mode="after")
def set_name(self) -> Any:
    """Force dump of `name` property to allow de-serialization from DType model"""
    self.model_fields_set.add("name")
    return self

to_narwhals() ¤

Get equivalent Narwhals data type

Source code in laktory/models/dtypes.py
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
def to_narwhals(self):
    """Get equivalent Narwhals data type"""
    nw_dtypes = nw.dtypes
    _type = self.name

    # Complex types
    if _type in "Array":
        return nw_dtypes.Array(inner=self.inner.to_narwhals(), shape=self.shape)

    if _type == "List":
        return nw_dtypes.List(inner=self.inner.to_narwhals())

    if _type == "Struct":
        fields = []
        for field in self.fields:
            fields += [nw.Field(name=field.name, dtype=field.dtype.to_narwhals())]
        return nw_dtypes.Struct(fields)

    if hasattr(nw_dtypes, _type):
        return getattr(nw_dtypes, _type)()

    # Not Found
    raise ValueError(f"Data type with name '{self.name}' is not supported")

to_polars() ¤

Get equivalent Polars data type

Source code in laktory/models/dtypes.py
240
241
242
243
244
245
246
247
def to_polars(self):
    """Get equivalent Polars data type"""
    from narwhals._polars.utils import narwhals_to_native_dtype

    return narwhals_to_native_dtype(
        dtype=self.to_narwhals(),
        version=nw._utils.Version.MAIN,
    )

to_pyspark() ¤

Get equivalent Spark data type

Source code in laktory/models/dtypes.py
225
226
227
228
229
230
231
232
233
234
235
236
237
238
def to_pyspark(self):
    """Get equivalent Spark data type"""
    import pyspark.sql.types as T
    from narwhals._spark_like.utils import narwhals_to_native_dtype

    from laktory import get_spark_session

    spark = get_spark_session()
    return narwhals_to_native_dtype(
        dtype=self.to_narwhals(),
        version=nw._utils.Version.MAIN,
        spark_types=T,
        session=spark,
    )

laktory.models.dtypes.Boolean ¤

Bases: SpecificDType

PARAMETER DESCRIPTION
category

Data type category

TYPE: Literal['NUMERIC', 'STRING', 'STRUCT'] | VariableType DEFAULT: 'NUMERIC'

fields

Definition of fields for Struct type.

TYPE: list[DField | VariableType] | VariableType DEFAULT: None

inner

Data type for sub-elements for Array or List types.

TYPE: str | DType | VariableType DEFAULT: None

name

Data type name.

TYPE: str | VariableType DEFAULT: 'Boolean'

shape

Definition of shape for Array type.

TYPE: int | list[int] | VariableType DEFAULT: None

METHOD DESCRIPTION
set_name

Force dump of name property to allow de-serialization from DType model

to_narwhals

Get equivalent Narwhals data type

to_polars

Get equivalent Polars data type

to_pyspark

Get equivalent Spark data type

set_name() ¤

Force dump of name property to allow de-serialization from DType model

Source code in laktory/models/dtypes.py
254
255
256
257
258
@model_validator(mode="after")
def set_name(self) -> Any:
    """Force dump of `name` property to allow de-serialization from DType model"""
    self.model_fields_set.add("name")
    return self

to_narwhals() ¤

Get equivalent Narwhals data type

Source code in laktory/models/dtypes.py
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
def to_narwhals(self):
    """Get equivalent Narwhals data type"""
    nw_dtypes = nw.dtypes
    _type = self.name

    # Complex types
    if _type in "Array":
        return nw_dtypes.Array(inner=self.inner.to_narwhals(), shape=self.shape)

    if _type == "List":
        return nw_dtypes.List(inner=self.inner.to_narwhals())

    if _type == "Struct":
        fields = []
        for field in self.fields:
            fields += [nw.Field(name=field.name, dtype=field.dtype.to_narwhals())]
        return nw_dtypes.Struct(fields)

    if hasattr(nw_dtypes, _type):
        return getattr(nw_dtypes, _type)()

    # Not Found
    raise ValueError(f"Data type with name '{self.name}' is not supported")

to_polars() ¤

Get equivalent Polars data type

Source code in laktory/models/dtypes.py
240
241
242
243
244
245
246
247
def to_polars(self):
    """Get equivalent Polars data type"""
    from narwhals._polars.utils import narwhals_to_native_dtype

    return narwhals_to_native_dtype(
        dtype=self.to_narwhals(),
        version=nw._utils.Version.MAIN,
    )

to_pyspark() ¤

Get equivalent Spark data type

Source code in laktory/models/dtypes.py
225
226
227
228
229
230
231
232
233
234
235
236
237
238
def to_pyspark(self):
    """Get equivalent Spark data type"""
    import pyspark.sql.types as T
    from narwhals._spark_like.utils import narwhals_to_native_dtype

    from laktory import get_spark_session

    spark = get_spark_session()
    return narwhals_to_native_dtype(
        dtype=self.to_narwhals(),
        version=nw._utils.Version.MAIN,
        spark_types=T,
        session=spark,
    )

laktory.models.dtypes.Object ¤

Bases: SpecificDType

PARAMETER DESCRIPTION
category

Data type category

TYPE: Literal['NUMERIC', 'STRING', 'STRUCT'] | VariableType DEFAULT: 'NUMERIC'

fields

Definition of fields for Struct type.

TYPE: list[DField | VariableType] | VariableType DEFAULT: None

inner

Data type for sub-elements for Array or List types.

TYPE: str | DType | VariableType DEFAULT: None

name

Data type name.

TYPE: str | VariableType DEFAULT: 'Object'

shape

Definition of shape for Array type.

TYPE: int | list[int] | VariableType DEFAULT: None

METHOD DESCRIPTION
set_name

Force dump of name property to allow de-serialization from DType model

to_narwhals

Get equivalent Narwhals data type

to_polars

Get equivalent Polars data type

to_pyspark

Get equivalent Spark data type

set_name() ¤

Force dump of name property to allow de-serialization from DType model

Source code in laktory/models/dtypes.py
254
255
256
257
258
@model_validator(mode="after")
def set_name(self) -> Any:
    """Force dump of `name` property to allow de-serialization from DType model"""
    self.model_fields_set.add("name")
    return self

to_narwhals() ¤

Get equivalent Narwhals data type

Source code in laktory/models/dtypes.py
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
def to_narwhals(self):
    """Get equivalent Narwhals data type"""
    nw_dtypes = nw.dtypes
    _type = self.name

    # Complex types
    if _type in "Array":
        return nw_dtypes.Array(inner=self.inner.to_narwhals(), shape=self.shape)

    if _type == "List":
        return nw_dtypes.List(inner=self.inner.to_narwhals())

    if _type == "Struct":
        fields = []
        for field in self.fields:
            fields += [nw.Field(name=field.name, dtype=field.dtype.to_narwhals())]
        return nw_dtypes.Struct(fields)

    if hasattr(nw_dtypes, _type):
        return getattr(nw_dtypes, _type)()

    # Not Found
    raise ValueError(f"Data type with name '{self.name}' is not supported")

to_polars() ¤

Get equivalent Polars data type

Source code in laktory/models/dtypes.py
240
241
242
243
244
245
246
247
def to_polars(self):
    """Get equivalent Polars data type"""
    from narwhals._polars.utils import narwhals_to_native_dtype

    return narwhals_to_native_dtype(
        dtype=self.to_narwhals(),
        version=nw._utils.Version.MAIN,
    )

to_pyspark() ¤

Get equivalent Spark data type

Source code in laktory/models/dtypes.py
225
226
227
228
229
230
231
232
233
234
235
236
237
238
def to_pyspark(self):
    """Get equivalent Spark data type"""
    import pyspark.sql.types as T
    from narwhals._spark_like.utils import narwhals_to_native_dtype

    from laktory import get_spark_session

    spark = get_spark_session()
    return narwhals_to_native_dtype(
        dtype=self.to_narwhals(),
        version=nw._utils.Version.MAIN,
        spark_types=T,
        session=spark,
    )

laktory.models.dtypes.Categorical ¤

Bases: SpecificDType

PARAMETER DESCRIPTION
category

Data type category

TYPE: Literal['NUMERIC', 'STRING', 'STRUCT'] | VariableType DEFAULT: 'NUMERIC'

fields

Definition of fields for Struct type.

TYPE: list[DField | VariableType] | VariableType DEFAULT: None

inner

Data type for sub-elements for Array or List types.

TYPE: str | DType | VariableType DEFAULT: None

name

Data type name.

TYPE: str | VariableType DEFAULT: 'Categorical'

shape

Definition of shape for Array type.

TYPE: int | list[int] | VariableType DEFAULT: None

METHOD DESCRIPTION
set_name

Force dump of name property to allow de-serialization from DType model

to_narwhals

Get equivalent Narwhals data type

to_polars

Get equivalent Polars data type

to_pyspark

Get equivalent Spark data type

set_name() ¤

Force dump of name property to allow de-serialization from DType model

Source code in laktory/models/dtypes.py
254
255
256
257
258
@model_validator(mode="after")
def set_name(self) -> Any:
    """Force dump of `name` property to allow de-serialization from DType model"""
    self.model_fields_set.add("name")
    return self

to_narwhals() ¤

Get equivalent Narwhals data type

Source code in laktory/models/dtypes.py
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
def to_narwhals(self):
    """Get equivalent Narwhals data type"""
    nw_dtypes = nw.dtypes
    _type = self.name

    # Complex types
    if _type in "Array":
        return nw_dtypes.Array(inner=self.inner.to_narwhals(), shape=self.shape)

    if _type == "List":
        return nw_dtypes.List(inner=self.inner.to_narwhals())

    if _type == "Struct":
        fields = []
        for field in self.fields:
            fields += [nw.Field(name=field.name, dtype=field.dtype.to_narwhals())]
        return nw_dtypes.Struct(fields)

    if hasattr(nw_dtypes, _type):
        return getattr(nw_dtypes, _type)()

    # Not Found
    raise ValueError(f"Data type with name '{self.name}' is not supported")

to_polars() ¤

Get equivalent Polars data type

Source code in laktory/models/dtypes.py
240
241
242
243
244
245
246
247
def to_polars(self):
    """Get equivalent Polars data type"""
    from narwhals._polars.utils import narwhals_to_native_dtype

    return narwhals_to_native_dtype(
        dtype=self.to_narwhals(),
        version=nw._utils.Version.MAIN,
    )

to_pyspark() ¤

Get equivalent Spark data type

Source code in laktory/models/dtypes.py
225
226
227
228
229
230
231
232
233
234
235
236
237
238
def to_pyspark(self):
    """Get equivalent Spark data type"""
    import pyspark.sql.types as T
    from narwhals._spark_like.utils import narwhals_to_native_dtype

    from laktory import get_spark_session

    spark = get_spark_session()
    return narwhals_to_native_dtype(
        dtype=self.to_narwhals(),
        version=nw._utils.Version.MAIN,
        spark_types=T,
        session=spark,
    )

laktory.models.dtypes.Enum ¤

Bases: SpecificDType

PARAMETER DESCRIPTION
category

Data type category

TYPE: Literal['NUMERIC', 'STRING', 'STRUCT'] | VariableType DEFAULT: 'NUMERIC'

fields

Definition of fields for Struct type.

TYPE: list[DField | VariableType] | VariableType DEFAULT: None

inner

Data type for sub-elements for Array or List types.

TYPE: str | DType | VariableType DEFAULT: None

name

Data type name.

TYPE: str | VariableType DEFAULT: 'Enum'

shape

Definition of shape for Array type.

TYPE: int | list[int] | VariableType DEFAULT: None

METHOD DESCRIPTION
set_name

Force dump of name property to allow de-serialization from DType model

to_narwhals

Get equivalent Narwhals data type

to_polars

Get equivalent Polars data type

to_pyspark

Get equivalent Spark data type

set_name() ¤

Force dump of name property to allow de-serialization from DType model

Source code in laktory/models/dtypes.py
254
255
256
257
258
@model_validator(mode="after")
def set_name(self) -> Any:
    """Force dump of `name` property to allow de-serialization from DType model"""
    self.model_fields_set.add("name")
    return self

to_narwhals() ¤

Get equivalent Narwhals data type

Source code in laktory/models/dtypes.py
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
def to_narwhals(self):
    """Get equivalent Narwhals data type"""
    nw_dtypes = nw.dtypes
    _type = self.name

    # Complex types
    if _type in "Array":
        return nw_dtypes.Array(inner=self.inner.to_narwhals(), shape=self.shape)

    if _type == "List":
        return nw_dtypes.List(inner=self.inner.to_narwhals())

    if _type == "Struct":
        fields = []
        for field in self.fields:
            fields += [nw.Field(name=field.name, dtype=field.dtype.to_narwhals())]
        return nw_dtypes.Struct(fields)

    if hasattr(nw_dtypes, _type):
        return getattr(nw_dtypes, _type)()

    # Not Found
    raise ValueError(f"Data type with name '{self.name}' is not supported")

to_polars() ¤

Get equivalent Polars data type

Source code in laktory/models/dtypes.py
240
241
242
243
244
245
246
247
def to_polars(self):
    """Get equivalent Polars data type"""
    from narwhals._polars.utils import narwhals_to_native_dtype

    return narwhals_to_native_dtype(
        dtype=self.to_narwhals(),
        version=nw._utils.Version.MAIN,
    )

to_pyspark() ¤

Get equivalent Spark data type

Source code in laktory/models/dtypes.py
225
226
227
228
229
230
231
232
233
234
235
236
237
238
def to_pyspark(self):
    """Get equivalent Spark data type"""
    import pyspark.sql.types as T
    from narwhals._spark_like.utils import narwhals_to_native_dtype

    from laktory import get_spark_session

    spark = get_spark_session()
    return narwhals_to_native_dtype(
        dtype=self.to_narwhals(),
        version=nw._utils.Version.MAIN,
        spark_types=T,
        session=spark,
    )

laktory.models.dtypes.Datetime ¤

Bases: SpecificDType

PARAMETER DESCRIPTION
category

Data type category

TYPE: Literal['NUMERIC', 'STRING', 'STRUCT'] | VariableType DEFAULT: 'NUMERIC'

fields

Definition of fields for Struct type.

TYPE: list[DField | VariableType] | VariableType DEFAULT: None

inner

Data type for sub-elements for Array or List types.

TYPE: str | DType | VariableType DEFAULT: None

name

Data type name.

TYPE: str | VariableType DEFAULT: 'Datetime'

shape

Definition of shape for Array type.

TYPE: int | list[int] | VariableType DEFAULT: None

METHOD DESCRIPTION
set_name

Force dump of name property to allow de-serialization from DType model

to_narwhals

Get equivalent Narwhals data type

to_polars

Get equivalent Polars data type

to_pyspark

Get equivalent Spark data type

set_name() ¤

Force dump of name property to allow de-serialization from DType model

Source code in laktory/models/dtypes.py
254
255
256
257
258
@model_validator(mode="after")
def set_name(self) -> Any:
    """Force dump of `name` property to allow de-serialization from DType model"""
    self.model_fields_set.add("name")
    return self

to_narwhals() ¤

Get equivalent Narwhals data type

Source code in laktory/models/dtypes.py
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
def to_narwhals(self):
    """Get equivalent Narwhals data type"""
    nw_dtypes = nw.dtypes
    _type = self.name

    # Complex types
    if _type in "Array":
        return nw_dtypes.Array(inner=self.inner.to_narwhals(), shape=self.shape)

    if _type == "List":
        return nw_dtypes.List(inner=self.inner.to_narwhals())

    if _type == "Struct":
        fields = []
        for field in self.fields:
            fields += [nw.Field(name=field.name, dtype=field.dtype.to_narwhals())]
        return nw_dtypes.Struct(fields)

    if hasattr(nw_dtypes, _type):
        return getattr(nw_dtypes, _type)()

    # Not Found
    raise ValueError(f"Data type with name '{self.name}' is not supported")

to_polars() ¤

Get equivalent Polars data type

Source code in laktory/models/dtypes.py
240
241
242
243
244
245
246
247
def to_polars(self):
    """Get equivalent Polars data type"""
    from narwhals._polars.utils import narwhals_to_native_dtype

    return narwhals_to_native_dtype(
        dtype=self.to_narwhals(),
        version=nw._utils.Version.MAIN,
    )

to_pyspark() ¤

Get equivalent Spark data type

Source code in laktory/models/dtypes.py
225
226
227
228
229
230
231
232
233
234
235
236
237
238
def to_pyspark(self):
    """Get equivalent Spark data type"""
    import pyspark.sql.types as T
    from narwhals._spark_like.utils import narwhals_to_native_dtype

    from laktory import get_spark_session

    spark = get_spark_session()
    return narwhals_to_native_dtype(
        dtype=self.to_narwhals(),
        version=nw._utils.Version.MAIN,
        spark_types=T,
        session=spark,
    )

laktory.models.dtypes.Duration ¤

Bases: SpecificDType

PARAMETER DESCRIPTION
category

Data type category

TYPE: Literal['NUMERIC', 'STRING', 'STRUCT'] | VariableType DEFAULT: 'NUMERIC'

fields

Definition of fields for Struct type.

TYPE: list[DField | VariableType] | VariableType DEFAULT: None

inner

Data type for sub-elements for Array or List types.

TYPE: str | DType | VariableType DEFAULT: None

name

Data type name.

TYPE: str | VariableType DEFAULT: 'Duration'

shape

Definition of shape for Array type.

TYPE: int | list[int] | VariableType DEFAULT: None

METHOD DESCRIPTION
set_name

Force dump of name property to allow de-serialization from DType model

to_narwhals

Get equivalent Narwhals data type

to_polars

Get equivalent Polars data type

to_pyspark

Get equivalent Spark data type

set_name() ¤

Force dump of name property to allow de-serialization from DType model

Source code in laktory/models/dtypes.py
254
255
256
257
258
@model_validator(mode="after")
def set_name(self) -> Any:
    """Force dump of `name` property to allow de-serialization from DType model"""
    self.model_fields_set.add("name")
    return self

to_narwhals() ¤

Get equivalent Narwhals data type

Source code in laktory/models/dtypes.py
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
def to_narwhals(self):
    """Get equivalent Narwhals data type"""
    nw_dtypes = nw.dtypes
    _type = self.name

    # Complex types
    if _type in "Array":
        return nw_dtypes.Array(inner=self.inner.to_narwhals(), shape=self.shape)

    if _type == "List":
        return nw_dtypes.List(inner=self.inner.to_narwhals())

    if _type == "Struct":
        fields = []
        for field in self.fields:
            fields += [nw.Field(name=field.name, dtype=field.dtype.to_narwhals())]
        return nw_dtypes.Struct(fields)

    if hasattr(nw_dtypes, _type):
        return getattr(nw_dtypes, _type)()

    # Not Found
    raise ValueError(f"Data type with name '{self.name}' is not supported")

to_polars() ¤

Get equivalent Polars data type

Source code in laktory/models/dtypes.py
240
241
242
243
244
245
246
247
def to_polars(self):
    """Get equivalent Polars data type"""
    from narwhals._polars.utils import narwhals_to_native_dtype

    return narwhals_to_native_dtype(
        dtype=self.to_narwhals(),
        version=nw._utils.Version.MAIN,
    )

to_pyspark() ¤

Get equivalent Spark data type

Source code in laktory/models/dtypes.py
225
226
227
228
229
230
231
232
233
234
235
236
237
238
def to_pyspark(self):
    """Get equivalent Spark data type"""
    import pyspark.sql.types as T
    from narwhals._spark_like.utils import narwhals_to_native_dtype

    from laktory import get_spark_session

    spark = get_spark_session()
    return narwhals_to_native_dtype(
        dtype=self.to_narwhals(),
        version=nw._utils.Version.MAIN,
        spark_types=T,
        session=spark,
    )

laktory.models.dtypes.Date ¤

Bases: SpecificDType

PARAMETER DESCRIPTION
category

Data type category

TYPE: Literal['NUMERIC', 'STRING', 'STRUCT'] | VariableType DEFAULT: 'NUMERIC'

fields

Definition of fields for Struct type.

TYPE: list[DField | VariableType] | VariableType DEFAULT: None

inner

Data type for sub-elements for Array or List types.

TYPE: str | DType | VariableType DEFAULT: None

name

Data type name.

TYPE: str | VariableType DEFAULT: 'Date'

shape

Definition of shape for Array type.

TYPE: int | list[int] | VariableType DEFAULT: None

METHOD DESCRIPTION
set_name

Force dump of name property to allow de-serialization from DType model

to_narwhals

Get equivalent Narwhals data type

to_polars

Get equivalent Polars data type

to_pyspark

Get equivalent Spark data type

set_name() ¤

Force dump of name property to allow de-serialization from DType model

Source code in laktory/models/dtypes.py
254
255
256
257
258
@model_validator(mode="after")
def set_name(self) -> Any:
    """Force dump of `name` property to allow de-serialization from DType model"""
    self.model_fields_set.add("name")
    return self

to_narwhals() ¤

Get equivalent Narwhals data type

Source code in laktory/models/dtypes.py
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
def to_narwhals(self):
    """Get equivalent Narwhals data type"""
    nw_dtypes = nw.dtypes
    _type = self.name

    # Complex types
    if _type in "Array":
        return nw_dtypes.Array(inner=self.inner.to_narwhals(), shape=self.shape)

    if _type == "List":
        return nw_dtypes.List(inner=self.inner.to_narwhals())

    if _type == "Struct":
        fields = []
        for field in self.fields:
            fields += [nw.Field(name=field.name, dtype=field.dtype.to_narwhals())]
        return nw_dtypes.Struct(fields)

    if hasattr(nw_dtypes, _type):
        return getattr(nw_dtypes, _type)()

    # Not Found
    raise ValueError(f"Data type with name '{self.name}' is not supported")

to_polars() ¤

Get equivalent Polars data type

Source code in laktory/models/dtypes.py
240
241
242
243
244
245
246
247
def to_polars(self):
    """Get equivalent Polars data type"""
    from narwhals._polars.utils import narwhals_to_native_dtype

    return narwhals_to_native_dtype(
        dtype=self.to_narwhals(),
        version=nw._utils.Version.MAIN,
    )

to_pyspark() ¤

Get equivalent Spark data type

Source code in laktory/models/dtypes.py
225
226
227
228
229
230
231
232
233
234
235
236
237
238
def to_pyspark(self):
    """Get equivalent Spark data type"""
    import pyspark.sql.types as T
    from narwhals._spark_like.utils import narwhals_to_native_dtype

    from laktory import get_spark_session

    spark = get_spark_session()
    return narwhals_to_native_dtype(
        dtype=self.to_narwhals(),
        version=nw._utils.Version.MAIN,
        spark_types=T,
        session=spark,
    )