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

time_unit

Time unit for Datetime or Duration types (e.g., 'us', 'ms', 'ns').

TYPE: str | None | VariableType DEFAULT: None

time_zone

Time zone for Datetime type (e.g., 'UTC', 'America/New_York'). Set to None for timezone-naive (TimestampNTZ in Spark).

TYPE: str | None | VariableType DEFAULT: 'UTC'

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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
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 _type == "Datetime":
        return nw_dtypes.Datetime(
            time_unit=self.time_unit or "us",
            time_zone=self.time_zone,
        )

    if _type == "Duration":
        return nw_dtypes.Duration(time_unit=self.time_unit or "us")

    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
272
273
274
275
276
277
278
279
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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
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

    # Narwhals rejects time zones that differ from the session's, so bypass
    # it for Datetime: None → TimestampNTZType (explicit TZ-naive),
    # any time zone → TimestampType (timezone-aware).
    if self.name == "Datetime":
        return T.TimestampNTZType() if self.time_zone is None else T.TimestampType()

    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

time_unit

Time unit for Datetime or Duration types (e.g., 'us', 'ms', 'ns').

TYPE: str | None | VariableType DEFAULT: None

time_zone

Time zone for Datetime type (e.g., 'UTC', 'America/New_York'). Set to None for timezone-naive (TimestampNTZ in Spark).

TYPE: str | None | VariableType DEFAULT: 'UTC'

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
286
287
288
289
290
@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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
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 _type == "Datetime":
        return nw_dtypes.Datetime(
            time_unit=self.time_unit or "us",
            time_zone=self.time_zone,
        )

    if _type == "Duration":
        return nw_dtypes.Duration(time_unit=self.time_unit or "us")

    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
272
273
274
275
276
277
278
279
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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
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

    # Narwhals rejects time zones that differ from the session's, so bypass
    # it for Datetime: None → TimestampNTZType (explicit TZ-naive),
    # any time zone → TimestampType (timezone-aware).
    if self.name == "Datetime":
        return T.TimestampNTZType() if self.time_zone is None else T.TimestampType()

    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

time_unit

Time unit for Datetime or Duration types (e.g., 'us', 'ms', 'ns').

TYPE: str | None | VariableType DEFAULT: None

time_zone

Time zone for Datetime type (e.g., 'UTC', 'America/New_York'). Set to None for timezone-naive (TimestampNTZ in Spark).

TYPE: str | None | VariableType DEFAULT: 'UTC'

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
286
287
288
289
290
@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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
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 _type == "Datetime":
        return nw_dtypes.Datetime(
            time_unit=self.time_unit or "us",
            time_zone=self.time_zone,
        )

    if _type == "Duration":
        return nw_dtypes.Duration(time_unit=self.time_unit or "us")

    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
272
273
274
275
276
277
278
279
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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
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

    # Narwhals rejects time zones that differ from the session's, so bypass
    # it for Datetime: None → TimestampNTZType (explicit TZ-naive),
    # any time zone → TimestampType (timezone-aware).
    if self.name == "Datetime":
        return T.TimestampNTZType() if self.time_zone is None else T.TimestampType()

    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

time_unit

Time unit for Datetime or Duration types (e.g., 'us', 'ms', 'ns').

TYPE: str | None | VariableType DEFAULT: None

time_zone

Time zone for Datetime type (e.g., 'UTC', 'America/New_York'). Set to None for timezone-naive (TimestampNTZ in Spark).

TYPE: str | None | VariableType DEFAULT: 'UTC'

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
286
287
288
289
290
@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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
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 _type == "Datetime":
        return nw_dtypes.Datetime(
            time_unit=self.time_unit or "us",
            time_zone=self.time_zone,
        )

    if _type == "Duration":
        return nw_dtypes.Duration(time_unit=self.time_unit or "us")

    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
272
273
274
275
276
277
278
279
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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
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

    # Narwhals rejects time zones that differ from the session's, so bypass
    # it for Datetime: None → TimestampNTZType (explicit TZ-naive),
    # any time zone → TimestampType (timezone-aware).
    if self.name == "Datetime":
        return T.TimestampNTZType() if self.time_zone is None else T.TimestampType()

    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

time_unit

Time unit for Datetime or Duration types (e.g., 'us', 'ms', 'ns').

TYPE: str | None | VariableType DEFAULT: None

time_zone

Time zone for Datetime type (e.g., 'UTC', 'America/New_York'). Set to None for timezone-naive (TimestampNTZ in Spark).

TYPE: str | None | VariableType DEFAULT: 'UTC'

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
286
287
288
289
290
@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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
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 _type == "Datetime":
        return nw_dtypes.Datetime(
            time_unit=self.time_unit or "us",
            time_zone=self.time_zone,
        )

    if _type == "Duration":
        return nw_dtypes.Duration(time_unit=self.time_unit or "us")

    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
272
273
274
275
276
277
278
279
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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
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

    # Narwhals rejects time zones that differ from the session's, so bypass
    # it for Datetime: None → TimestampNTZType (explicit TZ-naive),
    # any time zone → TimestampType (timezone-aware).
    if self.name == "Datetime":
        return T.TimestampNTZType() if self.time_zone is None else T.TimestampType()

    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

time_unit

Time unit for Datetime or Duration types (e.g., 'us', 'ms', 'ns').

TYPE: str | None | VariableType DEFAULT: None

time_zone

Time zone for Datetime type (e.g., 'UTC', 'America/New_York'). Set to None for timezone-naive (TimestampNTZ in Spark).

TYPE: str | None | VariableType DEFAULT: 'UTC'

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
286
287
288
289
290
@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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
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 _type == "Datetime":
        return nw_dtypes.Datetime(
            time_unit=self.time_unit or "us",
            time_zone=self.time_zone,
        )

    if _type == "Duration":
        return nw_dtypes.Duration(time_unit=self.time_unit or "us")

    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
272
273
274
275
276
277
278
279
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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
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

    # Narwhals rejects time zones that differ from the session's, so bypass
    # it for Datetime: None → TimestampNTZType (explicit TZ-naive),
    # any time zone → TimestampType (timezone-aware).
    if self.name == "Datetime":
        return T.TimestampNTZType() if self.time_zone is None else T.TimestampType()

    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

time_unit

Time unit for Datetime or Duration types (e.g., 'us', 'ms', 'ns').

TYPE: str | None | VariableType DEFAULT: None

time_zone

Time zone for Datetime type (e.g., 'UTC', 'America/New_York'). Set to None for timezone-naive (TimestampNTZ in Spark).

TYPE: str | None | VariableType DEFAULT: 'UTC'

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
286
287
288
289
290
@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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
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 _type == "Datetime":
        return nw_dtypes.Datetime(
            time_unit=self.time_unit or "us",
            time_zone=self.time_zone,
        )

    if _type == "Duration":
        return nw_dtypes.Duration(time_unit=self.time_unit or "us")

    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
272
273
274
275
276
277
278
279
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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
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

    # Narwhals rejects time zones that differ from the session's, so bypass
    # it for Datetime: None → TimestampNTZType (explicit TZ-naive),
    # any time zone → TimestampType (timezone-aware).
    if self.name == "Datetime":
        return T.TimestampNTZType() if self.time_zone is None else T.TimestampType()

    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

time_unit

Time unit for Datetime or Duration types (e.g., 'us', 'ms', 'ns').

TYPE: str | None | VariableType DEFAULT: None

time_zone

Time zone for Datetime type (e.g., 'UTC', 'America/New_York'). Set to None for timezone-naive (TimestampNTZ in Spark).

TYPE: str | None | VariableType DEFAULT: 'UTC'

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
286
287
288
289
290
@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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
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 _type == "Datetime":
        return nw_dtypes.Datetime(
            time_unit=self.time_unit or "us",
            time_zone=self.time_zone,
        )

    if _type == "Duration":
        return nw_dtypes.Duration(time_unit=self.time_unit or "us")

    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
272
273
274
275
276
277
278
279
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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
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

    # Narwhals rejects time zones that differ from the session's, so bypass
    # it for Datetime: None → TimestampNTZType (explicit TZ-naive),
    # any time zone → TimestampType (timezone-aware).
    if self.name == "Datetime":
        return T.TimestampNTZType() if self.time_zone is None else T.TimestampType()

    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

time_unit

Time unit for Datetime or Duration types (e.g., 'us', 'ms', 'ns').

TYPE: str | None | VariableType DEFAULT: None

time_zone

Time zone for Datetime type (e.g., 'UTC', 'America/New_York'). Set to None for timezone-naive (TimestampNTZ in Spark).

TYPE: str | None | VariableType DEFAULT: 'UTC'

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
286
287
288
289
290
@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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
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 _type == "Datetime":
        return nw_dtypes.Datetime(
            time_unit=self.time_unit or "us",
            time_zone=self.time_zone,
        )

    if _type == "Duration":
        return nw_dtypes.Duration(time_unit=self.time_unit or "us")

    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
272
273
274
275
276
277
278
279
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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
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

    # Narwhals rejects time zones that differ from the session's, so bypass
    # it for Datetime: None → TimestampNTZType (explicit TZ-naive),
    # any time zone → TimestampType (timezone-aware).
    if self.name == "Datetime":
        return T.TimestampNTZType() if self.time_zone is None else T.TimestampType()

    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

time_unit

Time unit for Datetime or Duration types (e.g., 'us', 'ms', 'ns').

TYPE: str | None | VariableType DEFAULT: None

time_zone

Time zone for Datetime type (e.g., 'UTC', 'America/New_York'). Set to None for timezone-naive (TimestampNTZ in Spark).

TYPE: str | None | VariableType DEFAULT: 'UTC'

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
286
287
288
289
290
@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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
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 _type == "Datetime":
        return nw_dtypes.Datetime(
            time_unit=self.time_unit or "us",
            time_zone=self.time_zone,
        )

    if _type == "Duration":
        return nw_dtypes.Duration(time_unit=self.time_unit or "us")

    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
272
273
274
275
276
277
278
279
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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
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

    # Narwhals rejects time zones that differ from the session's, so bypass
    # it for Datetime: None → TimestampNTZType (explicit TZ-naive),
    # any time zone → TimestampType (timezone-aware).
    if self.name == "Datetime":
        return T.TimestampNTZType() if self.time_zone is None else T.TimestampType()

    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

time_unit

Time unit for Datetime or Duration types (e.g., 'us', 'ms', 'ns').

TYPE: str | None | VariableType DEFAULT: None

time_zone

Time zone for Datetime type (e.g., 'UTC', 'America/New_York'). Set to None for timezone-naive (TimestampNTZ in Spark).

TYPE: str | None | VariableType DEFAULT: 'UTC'

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
286
287
288
289
290
@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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
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 _type == "Datetime":
        return nw_dtypes.Datetime(
            time_unit=self.time_unit or "us",
            time_zone=self.time_zone,
        )

    if _type == "Duration":
        return nw_dtypes.Duration(time_unit=self.time_unit or "us")

    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
272
273
274
275
276
277
278
279
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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
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

    # Narwhals rejects time zones that differ from the session's, so bypass
    # it for Datetime: None → TimestampNTZType (explicit TZ-naive),
    # any time zone → TimestampType (timezone-aware).
    if self.name == "Datetime":
        return T.TimestampNTZType() if self.time_zone is None else T.TimestampType()

    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

time_unit

Time unit for Datetime or Duration types (e.g., 'us', 'ms', 'ns').

TYPE: str | None | VariableType DEFAULT: None

time_zone

Time zone for Datetime type (e.g., 'UTC', 'America/New_York'). Set to None for timezone-naive (TimestampNTZ in Spark).

TYPE: str | None | VariableType DEFAULT: 'UTC'

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
286
287
288
289
290
@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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
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 _type == "Datetime":
        return nw_dtypes.Datetime(
            time_unit=self.time_unit or "us",
            time_zone=self.time_zone,
        )

    if _type == "Duration":
        return nw_dtypes.Duration(time_unit=self.time_unit or "us")

    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
272
273
274
275
276
277
278
279
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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
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

    # Narwhals rejects time zones that differ from the session's, so bypass
    # it for Datetime: None → TimestampNTZType (explicit TZ-naive),
    # any time zone → TimestampType (timezone-aware).
    if self.name == "Datetime":
        return T.TimestampNTZType() if self.time_zone is None else T.TimestampType()

    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

time_unit

Time unit for Datetime or Duration types (e.g., 'us', 'ms', 'ns').

TYPE: str | None | VariableType DEFAULT: None

time_zone

Time zone for Datetime type (e.g., 'UTC', 'America/New_York'). Set to None for timezone-naive (TimestampNTZ in Spark).

TYPE: str | None | VariableType DEFAULT: 'UTC'

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
286
287
288
289
290
@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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
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 _type == "Datetime":
        return nw_dtypes.Datetime(
            time_unit=self.time_unit or "us",
            time_zone=self.time_zone,
        )

    if _type == "Duration":
        return nw_dtypes.Duration(time_unit=self.time_unit or "us")

    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
272
273
274
275
276
277
278
279
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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
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

    # Narwhals rejects time zones that differ from the session's, so bypass
    # it for Datetime: None → TimestampNTZType (explicit TZ-naive),
    # any time zone → TimestampType (timezone-aware).
    if self.name == "Datetime":
        return T.TimestampNTZType() if self.time_zone is None else T.TimestampType()

    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

time_unit

Time unit for Datetime or Duration types (e.g., 'us', 'ms', 'ns').

TYPE: str | None | VariableType DEFAULT: None

time_zone

Time zone for Datetime type (e.g., 'UTC', 'America/New_York'). Set to None for timezone-naive (TimestampNTZ in Spark).

TYPE: str | None | VariableType DEFAULT: 'UTC'

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
286
287
288
289
290
@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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
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 _type == "Datetime":
        return nw_dtypes.Datetime(
            time_unit=self.time_unit or "us",
            time_zone=self.time_zone,
        )

    if _type == "Duration":
        return nw_dtypes.Duration(time_unit=self.time_unit or "us")

    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
272
273
274
275
276
277
278
279
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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
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

    # Narwhals rejects time zones that differ from the session's, so bypass
    # it for Datetime: None → TimestampNTZType (explicit TZ-naive),
    # any time zone → TimestampType (timezone-aware).
    if self.name == "Datetime":
        return T.TimestampNTZType() if self.time_zone is None else T.TimestampType()

    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

time_unit

Time unit for Datetime or Duration types (e.g., 'us', 'ms', 'ns').

TYPE: str | None | VariableType DEFAULT: None

time_zone

Time zone for Datetime type (e.g., 'UTC', 'America/New_York'). Set to None for timezone-naive (TimestampNTZ in Spark).

TYPE: str | None | VariableType DEFAULT: 'UTC'

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
286
287
288
289
290
@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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
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 _type == "Datetime":
        return nw_dtypes.Datetime(
            time_unit=self.time_unit or "us",
            time_zone=self.time_zone,
        )

    if _type == "Duration":
        return nw_dtypes.Duration(time_unit=self.time_unit or "us")

    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
272
273
274
275
276
277
278
279
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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
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

    # Narwhals rejects time zones that differ from the session's, so bypass
    # it for Datetime: None → TimestampNTZType (explicit TZ-naive),
    # any time zone → TimestampType (timezone-aware).
    if self.name == "Datetime":
        return T.TimestampNTZType() if self.time_zone is None else T.TimestampType()

    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

time_unit

Time unit for Datetime or Duration types (e.g., 'us', 'ms', 'ns').

TYPE: str | None | VariableType DEFAULT: None

time_zone

Time zone for Datetime type (e.g., 'UTC', 'America/New_York'). Set to None for timezone-naive (TimestampNTZ in Spark).

TYPE: str | None | VariableType DEFAULT: 'UTC'

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
286
287
288
289
290
@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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
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 _type == "Datetime":
        return nw_dtypes.Datetime(
            time_unit=self.time_unit or "us",
            time_zone=self.time_zone,
        )

    if _type == "Duration":
        return nw_dtypes.Duration(time_unit=self.time_unit or "us")

    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
272
273
274
275
276
277
278
279
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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
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

    # Narwhals rejects time zones that differ from the session's, so bypass
    # it for Datetime: None → TimestampNTZType (explicit TZ-naive),
    # any time zone → TimestampType (timezone-aware).
    if self.name == "Datetime":
        return T.TimestampNTZType() if self.time_zone is None else T.TimestampType()

    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

time_unit

Time unit for Datetime or Duration types (e.g., 'us', 'ms', 'ns').

TYPE: str | None | VariableType DEFAULT: None

time_zone

Time zone for Datetime type (e.g., 'UTC', 'America/New_York'). Set to None for timezone-naive (TimestampNTZ in Spark).

TYPE: str | None | VariableType DEFAULT: 'UTC'

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
286
287
288
289
290
@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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
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 _type == "Datetime":
        return nw_dtypes.Datetime(
            time_unit=self.time_unit or "us",
            time_zone=self.time_zone,
        )

    if _type == "Duration":
        return nw_dtypes.Duration(time_unit=self.time_unit or "us")

    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
272
273
274
275
276
277
278
279
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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
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

    # Narwhals rejects time zones that differ from the session's, so bypass
    # it for Datetime: None → TimestampNTZType (explicit TZ-naive),
    # any time zone → TimestampType (timezone-aware).
    if self.name == "Datetime":
        return T.TimestampNTZType() if self.time_zone is None else T.TimestampType()

    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

time_unit

Time unit for Datetime or Duration types (e.g., 'us', 'ms', 'ns').

TYPE: str | None | VariableType DEFAULT: None

time_zone

Time zone for Datetime type (e.g., 'UTC', 'America/New_York'). Set to None for timezone-naive (TimestampNTZ in Spark).

TYPE: str | None | VariableType DEFAULT: 'UTC'

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
286
287
288
289
290
@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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
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 _type == "Datetime":
        return nw_dtypes.Datetime(
            time_unit=self.time_unit or "us",
            time_zone=self.time_zone,
        )

    if _type == "Duration":
        return nw_dtypes.Duration(time_unit=self.time_unit or "us")

    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
272
273
274
275
276
277
278
279
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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
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

    # Narwhals rejects time zones that differ from the session's, so bypass
    # it for Datetime: None → TimestampNTZType (explicit TZ-naive),
    # any time zone → TimestampType (timezone-aware).
    if self.name == "Datetime":
        return T.TimestampNTZType() if self.time_zone is None else T.TimestampType()

    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

time_unit

Time unit for Datetime or Duration types (e.g., 'us', 'ms', 'ns').

TYPE: str | None | VariableType DEFAULT: None

time_zone

Time zone for Datetime type (e.g., 'UTC', 'America/New_York'). Set to None for timezone-naive (TimestampNTZ in Spark).

TYPE: str | None | VariableType DEFAULT: 'UTC'

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
286
287
288
289
290
@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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
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 _type == "Datetime":
        return nw_dtypes.Datetime(
            time_unit=self.time_unit or "us",
            time_zone=self.time_zone,
        )

    if _type == "Duration":
        return nw_dtypes.Duration(time_unit=self.time_unit or "us")

    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
272
273
274
275
276
277
278
279
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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
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

    # Narwhals rejects time zones that differ from the session's, so bypass
    # it for Datetime: None → TimestampNTZType (explicit TZ-naive),
    # any time zone → TimestampType (timezone-aware).
    if self.name == "Datetime":
        return T.TimestampNTZType() if self.time_zone is None else T.TimestampType()

    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

time_unit

Time unit for Datetime or Duration types (e.g., 'us', 'ms', 'ns').

TYPE: str | None | VariableType DEFAULT: None

time_zone

Time zone for Datetime type (e.g., 'UTC', 'America/New_York'). Set to None for timezone-naive (TimestampNTZ in Spark).

TYPE: str | None | VariableType DEFAULT: 'UTC'

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
286
287
288
289
290
@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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
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 _type == "Datetime":
        return nw_dtypes.Datetime(
            time_unit=self.time_unit or "us",
            time_zone=self.time_zone,
        )

    if _type == "Duration":
        return nw_dtypes.Duration(time_unit=self.time_unit or "us")

    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
272
273
274
275
276
277
278
279
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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
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

    # Narwhals rejects time zones that differ from the session's, so bypass
    # it for Datetime: None → TimestampNTZType (explicit TZ-naive),
    # any time zone → TimestampType (timezone-aware).
    if self.name == "Datetime":
        return T.TimestampNTZType() if self.time_zone is None else T.TimestampType()

    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

time_unit

Time unit for Datetime or Duration types (e.g., 'us', 'ms', 'ns').

TYPE: str | None | VariableType DEFAULT: None

time_zone

Time zone for Datetime type (e.g., 'UTC', 'America/New_York'). Set to None for timezone-naive (TimestampNTZ in Spark).

TYPE: str | None | VariableType DEFAULT: 'UTC'

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
286
287
288
289
290
@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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
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 _type == "Datetime":
        return nw_dtypes.Datetime(
            time_unit=self.time_unit or "us",
            time_zone=self.time_zone,
        )

    if _type == "Duration":
        return nw_dtypes.Duration(time_unit=self.time_unit or "us")

    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
272
273
274
275
276
277
278
279
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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
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

    # Narwhals rejects time zones that differ from the session's, so bypass
    # it for Datetime: None → TimestampNTZType (explicit TZ-naive),
    # any time zone → TimestampType (timezone-aware).
    if self.name == "Datetime":
        return T.TimestampNTZType() if self.time_zone is None else T.TimestampType()

    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

time_unit

Time unit for Datetime or Duration types (e.g., 'us', 'ms', 'ns').

TYPE: str | None | VariableType DEFAULT: None

time_zone

Time zone for Datetime type (e.g., 'UTC', 'America/New_York'). Set to None for timezone-naive (TimestampNTZ in Spark).

TYPE: str | None | VariableType DEFAULT: 'UTC'

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
286
287
288
289
290
@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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
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 _type == "Datetime":
        return nw_dtypes.Datetime(
            time_unit=self.time_unit or "us",
            time_zone=self.time_zone,
        )

    if _type == "Duration":
        return nw_dtypes.Duration(time_unit=self.time_unit or "us")

    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
272
273
274
275
276
277
278
279
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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
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

    # Narwhals rejects time zones that differ from the session's, so bypass
    # it for Datetime: None → TimestampNTZType (explicit TZ-naive),
    # any time zone → TimestampType (timezone-aware).
    if self.name == "Datetime":
        return T.TimestampNTZType() if self.time_zone is None else T.TimestampType()

    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

time_unit

Time unit for Datetime or Duration types (e.g., 'us', 'ms', 'ns').

TYPE: str | None | VariableType DEFAULT: None

time_zone

Time zone for Datetime type (e.g., 'UTC', 'America/New_York'). Set to None for timezone-naive (TimestampNTZ in Spark).

TYPE: str | None | VariableType DEFAULT: 'UTC'

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
286
287
288
289
290
@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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
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 _type == "Datetime":
        return nw_dtypes.Datetime(
            time_unit=self.time_unit or "us",
            time_zone=self.time_zone,
        )

    if _type == "Duration":
        return nw_dtypes.Duration(time_unit=self.time_unit or "us")

    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
272
273
274
275
276
277
278
279
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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
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

    # Narwhals rejects time zones that differ from the session's, so bypass
    # it for Datetime: None → TimestampNTZType (explicit TZ-naive),
    # any time zone → TimestampType (timezone-aware).
    if self.name == "Datetime":
        return T.TimestampNTZType() if self.time_zone is None else T.TimestampType()

    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

time_unit

Time unit for Datetime or Duration types (e.g., 'us', 'ms', 'ns').

TYPE: str | None | VariableType DEFAULT: None

time_zone

Time zone for Datetime type (e.g., 'UTC', 'America/New_York'). Set to None for timezone-naive (TimestampNTZ in Spark).

TYPE: str | None | VariableType DEFAULT: 'UTC'

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
286
287
288
289
290
@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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
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 _type == "Datetime":
        return nw_dtypes.Datetime(
            time_unit=self.time_unit or "us",
            time_zone=self.time_zone,
        )

    if _type == "Duration":
        return nw_dtypes.Duration(time_unit=self.time_unit or "us")

    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
272
273
274
275
276
277
278
279
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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
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

    # Narwhals rejects time zones that differ from the session's, so bypass
    # it for Datetime: None → TimestampNTZType (explicit TZ-naive),
    # any time zone → TimestampType (timezone-aware).
    if self.name == "Datetime":
        return T.TimestampNTZType() if self.time_zone is None else T.TimestampType()

    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

time_unit

Time unit for Datetime or Duration types (e.g., 'us', 'ms', 'ns').

TYPE: str | None | VariableType DEFAULT: None

time_zone

Time zone for Datetime type (e.g., 'UTC', 'America/New_York'). Set to None for timezone-naive (TimestampNTZ in Spark).

TYPE: str | None | VariableType DEFAULT: 'UTC'

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
286
287
288
289
290
@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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
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 _type == "Datetime":
        return nw_dtypes.Datetime(
            time_unit=self.time_unit or "us",
            time_zone=self.time_zone,
        )

    if _type == "Duration":
        return nw_dtypes.Duration(time_unit=self.time_unit or "us")

    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
272
273
274
275
276
277
278
279
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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
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

    # Narwhals rejects time zones that differ from the session's, so bypass
    # it for Datetime: None → TimestampNTZType (explicit TZ-naive),
    # any time zone → TimestampType (timezone-aware).
    if self.name == "Datetime":
        return T.TimestampNTZType() if self.time_zone is None else T.TimestampType()

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