Skip to content

Data Types

This module contains classes for handling the different logical types that occur in databases.

All data type constructors take a nullable: bool parameter whose default value is True.

core

Classes

Any (DataType)

Values of any type.

Array (Variadic)

Array values.

Binary (Singleton, Variadic)

A type representing a sequence of bytes.

Boolean (Primitive)

True or False values.

Bounds (tuple)

The lower and upper bound of a fixed-size value.

DataType (Annotable, Comparable)

Base class for all data types.

DataType instances are immutable.

Attributes
name: str property readonly

Return the name of the data type.

Methods
cast(self, target, **kwargs)

Cast this data type to target.

castable(self, target, **kwargs)

Return whether this data type is castable to target.

to_pandas(ibis_dtype)

Convert ibis dtype to the pandas / numpy alternative

Date (Primitive)

Date values.

Decimal (DataType)

Fixed-precision decimal values.

Attributes
largest property readonly

Return the largest type of decimal.

precision

The number of decimal places values of this type can hold.

scale

The number of values after the decimal point.

Enum (DataType)

Enumeration values.

Float16 (Floating)

16-bit floating point numbers.

Float32 (Floating)

32-bit floating point numbers.

Float64 (Floating)

64-bit floating point numbers.

Floating (Primitive)

Floating point values.

Attributes
largest property readonly

Return the largest type of floating point values.

GeoSpatial (DataType)

Geospatial values.

Attributes
geotype

The specific geospatial type

srid

The spatial reference identifier.

Geography (GeoSpatial)

Geography values.

Geometry (GeoSpatial)

Geometry values.

INET (String)

IP addresses.

Int16 (SignedInteger)

Signed 16-bit integers.

Int32 (SignedInteger)

Signed 32-bit integers.

Int64 (SignedInteger)

Signed 64-bit integers.

Int8 (SignedInteger)

Signed 8-bit integers.

Integer (Primitive)

Integer values.

Interval (DataType)

Interval values.

Attributes
resolution property readonly

The interval unit's name.

unit

The time unit of the interval.

value_type

The underlying type of the stored values.

JSON (String)

JSON values.

JSONB (Binary)

JSON data stored in a binary representation.

This representation eliminates whitespace, duplicate keys, and does not preserve key ordering.

LineString (GeoSpatial)

A sequence of 2 or more points.

MACADDR (String)

Media Access Control (MAC) address of a network interface.

Map (Variadic)

Associative array values.

MultiLineString (GeoSpatial)

A set of one or more line strings.

MultiPoint (GeoSpatial)

A set of one or more points.

MultiPolygon (GeoSpatial)

A set of one or more polygons.

Null (Singleton, DataType)

Null values.

Point (GeoSpatial)

A point described by two coordinates.

Polygon (GeoSpatial)

A set of one or more closed line strings.

The first line string represents the shape (external ring) and the rest represent holes in that shape (internal rings).

Primitive (Singleton, DataType)

Values with known size.

Set (Variadic)

Set values.

SignedInteger (Integer)

Signed integer values.

Attributes
largest property readonly

Return the largest type of signed integer.

String (Singleton, Variadic)

A type representing a string.

Struct (DataType)

Structured values.

Attributes
pairs: Mapping[str, DataType] property readonly

Return a mapping from names to data type instances.

Returns:

Type Description
Mapping[str, DataType]

Mapping of field name to data type

Methods
from_dict(pairs, nullable=True) classmethod

Construct a Struct type from a dict.

Parameters:

Name Type Description Default
pairs Mapping[str, str | DataType]

A dict of field: type

required

Returns:

Type Description
Struct

Struct data type instance

from_tuples(pairs, nullable=True) classmethod

Construct a Struct type from pairs.

Parameters:

Name Type Description Default
pairs Iterable[tuple[str, str | DataType]]

An iterable of pairs of field name and type

required

Returns:

Type Description
Struct

Struct data type instance

Time (Primitive)

Time values.

Timestamp (DataType)

Timestamp values.

Attributes
timezone

The timezone of values of this type.

UInt16 (UnsignedInteger)

Unsigned 16-bit integers.

UInt32 (UnsignedInteger)

Unsigned 32-bit integers.

UInt64 (UnsignedInteger)

Unsigned 64-bit integers.

UInt8 (UnsignedInteger)

Unsigned 8-bit integers.

UUID (DataType)

A 128-bit number used to identify information in computer systems.

UnsignedInteger (Integer)

Unsigned integer values.

Attributes
largest property readonly

Return the largest type of unsigned integer.

Variadic (DataType)

Values with unknown size.

Functions

cast(source, target, **kwargs)

Attempts to implicitly cast from source dtype to target dtype

parse(text)

Parse a type from a str text.

The default maxsize parameter for caching is chosen to cache the most commonly used types--there are about 30--along with some capacity for less common but repeatedly-used complex types.

Parameters:

Name Type Description Default
text str

The type string to parse

required

Examples:

Parse an array type from a string

>>> import ibis
>>> import ibis.expr.datatypes as dt
>>> dt.parse("array<int64>")
Array(value_type=Int64(nullable=True), nullable=True)

You can avoid parsing altogether by constructing objects directly

>>> import ibis
>>> import ibis.expr.datatypes as dt
>>> ty = dt.parse("array<int64>")
>>> ty == dt.Array(dt.int64)
True

parse_type(*args, **kwargs)

DEPRECATED: parse_type is deprecated as of v4.0; use ibis.expr.datatypes.core.parse


Last update: August 5, 2022