Skip to content

ColumnType

Bases: ABC

The type of a column in a table.

Use the static factory methods to create instances of this class.

Methods:

Name Description
binary

Create a binary column type.

boolean

Create a boolean column type.

date

Create a date column type.

datetime

Create a datetime column type.

duration

Create a duration column type.

float32

Create a float32 column type (32-bit floating point number).

float64

Create a float64 column type (64-bit floating point number).

int16

Create an int16 column type (16-bit signed integer).

int32

Create an int32 column type (32-bit signed integer).

int64

Create an int64 column type (64-bit signed integer).

int8

Create an int8 column type (8-bit signed integer).

null

Create a null column type.

string

Create a string column type.

time

Create a time column type.

uint16

Create a uint16 column type (16-bit unsigned integer).

uint32

Create a uint32 column type (32-bit unsigned integer).

uint64

Create a uint64 column type (64-bit unsigned integer).

uint8

Create a uint8 column type (8-bit unsigned integer).

Attributes:

Name Type Description
is_float bool

Whether the column type is a floating point type.

is_int bool

Whether the column type is an integer type (signed or unsigned).

is_numeric bool

Whether the column type is a numeric type.

is_signed_int bool

Whether the column type is a signed integer type.

is_temporal bool

Whether the column type is a temporal type.

is_unsigned_int bool

Whether the column type is an unsigned integer type.

Source code in src/safeds/data/tabular/typing/_column_type.py
class ColumnType(ABC):
    """
    The type of a column in a table.

    Use the static factory methods to create instances of this class.
    """

    # ------------------------------------------------------------------------------------------------------------------
    # Factory methods
    # ------------------------------------------------------------------------------------------------------------------

    # Float --------------------------------------------------------------------

    @staticmethod
    def float32() -> ColumnType:
        """Create a `float32` column type (32-bit floating point number)."""
        import polars as pl

        from ._polars_column_type import _PolarsColumnType  # circular import

        return _PolarsColumnType(pl.Float32())

    @staticmethod
    def float64() -> ColumnType:
        """Create a `float64` column type (64-bit floating point number)."""
        import polars as pl

        from ._polars_column_type import _PolarsColumnType  # circular import

        return _PolarsColumnType(pl.Float64())

    # Signed int ---------------------------------------------------------------

    @staticmethod
    def int8() -> ColumnType:
        """Create an `int8` column type (8-bit signed integer)."""
        import polars as pl

        from ._polars_column_type import _PolarsColumnType  # circular import

        return _PolarsColumnType(pl.Int8())

    @staticmethod
    def int16() -> ColumnType:
        """Create an `int16` column type (16-bit signed integer)."""
        import polars as pl

        from ._polars_column_type import _PolarsColumnType  # circular import

        return _PolarsColumnType(pl.Int16())

    @staticmethod
    def int32() -> ColumnType:
        """Create an `int32` column type (32-bit signed integer)."""
        import polars as pl

        from ._polars_column_type import _PolarsColumnType  # circular import

        return _PolarsColumnType(pl.Int32())

    @staticmethod
    def int64() -> ColumnType:
        """Create an `int64` column type (64-bit signed integer)."""
        import polars as pl

        from ._polars_column_type import _PolarsColumnType  # circular import

        return _PolarsColumnType(pl.Int64())

    # Unsigned int -------------------------------------------------------------

    @staticmethod
    def uint8() -> ColumnType:
        """Create a `uint8` column type (8-bit unsigned integer)."""
        import polars as pl

        from ._polars_column_type import _PolarsColumnType  # circular import

        return _PolarsColumnType(pl.UInt8())

    @staticmethod
    def uint16() -> ColumnType:
        """Create a `uint16` column type (16-bit unsigned integer)."""
        import polars as pl

        from ._polars_column_type import _PolarsColumnType  # circular import

        return _PolarsColumnType(pl.UInt16())

    @staticmethod
    def uint32() -> ColumnType:
        """Create a `uint32` column type (32-bit unsigned integer)."""
        import polars as pl

        from ._polars_column_type import _PolarsColumnType  # circular import

        return _PolarsColumnType(pl.UInt32())

    @staticmethod
    def uint64() -> ColumnType:
        """Create a `uint64` column type (64-bit unsigned integer)."""
        import polars as pl

        from ._polars_column_type import _PolarsColumnType  # circular import

        return _PolarsColumnType(pl.UInt64())

    # Temporal -----------------------------------------------------------------

    @staticmethod
    def date() -> ColumnType:
        """Create a `date` column type."""
        import polars as pl

        from ._polars_column_type import _PolarsColumnType  # circular import

        return _PolarsColumnType(pl.Date())

    @staticmethod
    def datetime(*, time_zone: str | None = None) -> ColumnType:
        """
        Create a `datetime` column type.

        Parameters
        ----------
        time_zone:
            The time zone. If None, values are assumed to be in local time. This is different from setting the time zone
            to `"UTC"`. Any TZ identifier defined in the
            [tz database](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones) is valid.
        """
        import polars as pl

        from ._polars_column_type import _PolarsColumnType  # circular import

        _check_time_zone(time_zone)

        return _PolarsColumnType(pl.Datetime(time_zone=time_zone))

    @staticmethod
    def duration() -> ColumnType:
        """Create a `duration` column type."""
        import polars as pl

        from ._polars_column_type import _PolarsColumnType  # circular import

        return _PolarsColumnType(pl.Duration())

    @staticmethod
    def time() -> ColumnType:
        """Create a `time` column type."""
        import polars as pl

        from ._polars_column_type import _PolarsColumnType  # circular import

        return _PolarsColumnType(pl.Time())

    # String -------------------------------------------------------------------

    @staticmethod
    def string() -> ColumnType:
        """Create a `string` column type."""
        import polars as pl

        from ._polars_column_type import _PolarsColumnType  # circular import

        return _PolarsColumnType(pl.String())

    # Other --------------------------------------------------------------------

    @staticmethod
    def binary() -> ColumnType:
        """Create a `binary` column type."""
        import polars as pl

        from ._polars_column_type import _PolarsColumnType  # circular import

        return _PolarsColumnType(pl.Binary())

    @staticmethod
    def boolean() -> ColumnType:
        """Create a `boolean` column type."""
        import polars as pl

        from ._polars_column_type import _PolarsColumnType  # circular import

        return _PolarsColumnType(pl.Boolean())

    @staticmethod
    def null() -> ColumnType:
        """Create a `null` column type."""
        import polars as pl

        from ._polars_column_type import _PolarsColumnType  # circular import

        return _PolarsColumnType(pl.Null())

    # ------------------------------------------------------------------------------------------------------------------
    # Dunder methods
    # ------------------------------------------------------------------------------------------------------------------

    @abstractmethod
    def __eq__(self, other: object) -> bool: ...

    @abstractmethod
    def __hash__(self) -> int: ...

    @abstractmethod
    def __repr__(self) -> str: ...

    @abstractmethod
    def __sizeof__(self) -> int: ...

    @abstractmethod
    def __str__(self) -> str: ...

    # ------------------------------------------------------------------------------------------------------------------
    # Properties
    # ------------------------------------------------------------------------------------------------------------------

    @property
    @abstractmethod
    def is_float(self) -> bool:
        """
        Whether the column type is a floating point type.

        Examples
        --------
        >>> from safeds.data.tabular.typing import ColumnType
        >>> ColumnType.float32().is_float
        True

        >>> ColumnType.int8().is_float
        False
        """

    @property
    @abstractmethod
    def is_int(self) -> bool:
        """
        Whether the column type is an integer type (signed or unsigned).

        Examples
        --------
        >>> from safeds.data.tabular.typing import ColumnType
        >>> ColumnType.int8().is_int
        True

        >>> ColumnType.float32().is_int
        False
        """

    @property
    @abstractmethod
    def is_numeric(self) -> bool:
        """
        Whether the column type is a numeric type.

        Examples
        --------
        >>> from safeds.data.tabular.typing import ColumnType
        >>> ColumnType.float32().is_numeric
        True

        >>> ColumnType.string().is_numeric
        False
        """

    @property
    @abstractmethod
    def is_signed_int(self) -> bool:
        """
        Whether the column type is a signed integer type.

        Examples
        --------
        >>> from safeds.data.tabular.typing import ColumnType
        >>> ColumnType.int8().is_signed_int
        True

        >>> ColumnType.uint8().is_signed_int
        False
        """

    @property
    @abstractmethod
    def is_temporal(self) -> bool:
        """
        Whether the column type is a temporal type.

        Examples
        --------
        >>> from safeds.data.tabular.typing import ColumnType
        >>> ColumnType.date().is_temporal
        True

        >>> ColumnType.string().is_temporal
        False
        """

    @property
    @abstractmethod
    def is_unsigned_int(self) -> bool:
        """
        Whether the column type is an unsigned integer type.

        Examples
        --------
        >>> from safeds.data.tabular.typing import ColumnType
        >>> ColumnType.uint8().is_unsigned_int
        True

        >>> ColumnType.int8().is_unsigned_int
        False
        """

    # ------------------------------------------------------------------------------------------------------------------
    # Internal
    # ------------------------------------------------------------------------------------------------------------------

    @property
    @abstractmethod
    def _polars_data_type(self) -> pl.DataType:
        """The Polars expression that corresponds to this cell."""

is_float

Whether the column type is a floating point type.

Examples:

>>> from safeds.data.tabular.typing import ColumnType
>>> ColumnType.float32().is_float
True
>>> ColumnType.int8().is_float
False

is_int

Whether the column type is an integer type (signed or unsigned).

Examples:

>>> from safeds.data.tabular.typing import ColumnType
>>> ColumnType.int8().is_int
True
>>> ColumnType.float32().is_int
False

is_numeric

Whether the column type is a numeric type.

Examples:

>>> from safeds.data.tabular.typing import ColumnType
>>> ColumnType.float32().is_numeric
True
>>> ColumnType.string().is_numeric
False

is_signed_int

Whether the column type is a signed integer type.

Examples:

>>> from safeds.data.tabular.typing import ColumnType
>>> ColumnType.int8().is_signed_int
True
>>> ColumnType.uint8().is_signed_int
False

is_temporal

Whether the column type is a temporal type.

Examples:

>>> from safeds.data.tabular.typing import ColumnType
>>> ColumnType.date().is_temporal
True
>>> ColumnType.string().is_temporal
False

is_unsigned_int

Whether the column type is an unsigned integer type.

Examples:

>>> from safeds.data.tabular.typing import ColumnType
>>> ColumnType.uint8().is_unsigned_int
True
>>> ColumnType.int8().is_unsigned_int
False

binary

Create a binary column type.

Source code in src/safeds/data/tabular/typing/_column_type.py
@staticmethod
def binary() -> ColumnType:
    """Create a `binary` column type."""
    import polars as pl

    from ._polars_column_type import _PolarsColumnType  # circular import

    return _PolarsColumnType(pl.Binary())

boolean

Create a boolean column type.

Source code in src/safeds/data/tabular/typing/_column_type.py
@staticmethod
def boolean() -> ColumnType:
    """Create a `boolean` column type."""
    import polars as pl

    from ._polars_column_type import _PolarsColumnType  # circular import

    return _PolarsColumnType(pl.Boolean())

date

Create a date column type.

Source code in src/safeds/data/tabular/typing/_column_type.py
@staticmethod
def date() -> ColumnType:
    """Create a `date` column type."""
    import polars as pl

    from ._polars_column_type import _PolarsColumnType  # circular import

    return _PolarsColumnType(pl.Date())

datetime

Create a datetime column type.

Parameters:

Name Type Description Default
time_zone str | None

The time zone. If None, values are assumed to be in local time. This is different from setting the time zone to "UTC". Any TZ identifier defined in the tz database is valid.

None
Source code in src/safeds/data/tabular/typing/_column_type.py
@staticmethod
def datetime(*, time_zone: str | None = None) -> ColumnType:
    """
    Create a `datetime` column type.

    Parameters
    ----------
    time_zone:
        The time zone. If None, values are assumed to be in local time. This is different from setting the time zone
        to `"UTC"`. Any TZ identifier defined in the
        [tz database](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones) is valid.
    """
    import polars as pl

    from ._polars_column_type import _PolarsColumnType  # circular import

    _check_time_zone(time_zone)

    return _PolarsColumnType(pl.Datetime(time_zone=time_zone))

duration

Create a duration column type.

Source code in src/safeds/data/tabular/typing/_column_type.py
@staticmethod
def duration() -> ColumnType:
    """Create a `duration` column type."""
    import polars as pl

    from ._polars_column_type import _PolarsColumnType  # circular import

    return _PolarsColumnType(pl.Duration())

float32

Create a float32 column type (32-bit floating point number).

Source code in src/safeds/data/tabular/typing/_column_type.py
@staticmethod
def float32() -> ColumnType:
    """Create a `float32` column type (32-bit floating point number)."""
    import polars as pl

    from ._polars_column_type import _PolarsColumnType  # circular import

    return _PolarsColumnType(pl.Float32())

float64

Create a float64 column type (64-bit floating point number).

Source code in src/safeds/data/tabular/typing/_column_type.py
@staticmethod
def float64() -> ColumnType:
    """Create a `float64` column type (64-bit floating point number)."""
    import polars as pl

    from ._polars_column_type import _PolarsColumnType  # circular import

    return _PolarsColumnType(pl.Float64())

int16

Create an int16 column type (16-bit signed integer).

Source code in src/safeds/data/tabular/typing/_column_type.py
@staticmethod
def int16() -> ColumnType:
    """Create an `int16` column type (16-bit signed integer)."""
    import polars as pl

    from ._polars_column_type import _PolarsColumnType  # circular import

    return _PolarsColumnType(pl.Int16())

int32

Create an int32 column type (32-bit signed integer).

Source code in src/safeds/data/tabular/typing/_column_type.py
@staticmethod
def int32() -> ColumnType:
    """Create an `int32` column type (32-bit signed integer)."""
    import polars as pl

    from ._polars_column_type import _PolarsColumnType  # circular import

    return _PolarsColumnType(pl.Int32())

int64

Create an int64 column type (64-bit signed integer).

Source code in src/safeds/data/tabular/typing/_column_type.py
@staticmethod
def int64() -> ColumnType:
    """Create an `int64` column type (64-bit signed integer)."""
    import polars as pl

    from ._polars_column_type import _PolarsColumnType  # circular import

    return _PolarsColumnType(pl.Int64())

int8

Create an int8 column type (8-bit signed integer).

Source code in src/safeds/data/tabular/typing/_column_type.py
@staticmethod
def int8() -> ColumnType:
    """Create an `int8` column type (8-bit signed integer)."""
    import polars as pl

    from ._polars_column_type import _PolarsColumnType  # circular import

    return _PolarsColumnType(pl.Int8())

null

Create a null column type.

Source code in src/safeds/data/tabular/typing/_column_type.py
@staticmethod
def null() -> ColumnType:
    """Create a `null` column type."""
    import polars as pl

    from ._polars_column_type import _PolarsColumnType  # circular import

    return _PolarsColumnType(pl.Null())

string

Create a string column type.

Source code in src/safeds/data/tabular/typing/_column_type.py
@staticmethod
def string() -> ColumnType:
    """Create a `string` column type."""
    import polars as pl

    from ._polars_column_type import _PolarsColumnType  # circular import

    return _PolarsColumnType(pl.String())

time

Create a time column type.

Source code in src/safeds/data/tabular/typing/_column_type.py
@staticmethod
def time() -> ColumnType:
    """Create a `time` column type."""
    import polars as pl

    from ._polars_column_type import _PolarsColumnType  # circular import

    return _PolarsColumnType(pl.Time())

uint16

Create a uint16 column type (16-bit unsigned integer).

Source code in src/safeds/data/tabular/typing/_column_type.py
@staticmethod
def uint16() -> ColumnType:
    """Create a `uint16` column type (16-bit unsigned integer)."""
    import polars as pl

    from ._polars_column_type import _PolarsColumnType  # circular import

    return _PolarsColumnType(pl.UInt16())

uint32

Create a uint32 column type (32-bit unsigned integer).

Source code in src/safeds/data/tabular/typing/_column_type.py
@staticmethod
def uint32() -> ColumnType:
    """Create a `uint32` column type (32-bit unsigned integer)."""
    import polars as pl

    from ._polars_column_type import _PolarsColumnType  # circular import

    return _PolarsColumnType(pl.UInt32())

uint64

Create a uint64 column type (64-bit unsigned integer).

Source code in src/safeds/data/tabular/typing/_column_type.py
@staticmethod
def uint64() -> ColumnType:
    """Create a `uint64` column type (64-bit unsigned integer)."""
    import polars as pl

    from ._polars_column_type import _PolarsColumnType  # circular import

    return _PolarsColumnType(pl.UInt64())

uint8

Create a uint8 column type (8-bit unsigned integer).

Source code in src/safeds/data/tabular/typing/_column_type.py
@staticmethod
def uint8() -> ColumnType:
    """Create a `uint8` column type (8-bit unsigned integer)."""
    import polars as pl

    from ._polars_column_type import _PolarsColumnType  # circular import

    return _PolarsColumnType(pl.UInt8())