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

Array

Bases: Variadic, Parametric

Array values.

Binary

Bases: Variadic, Singleton

A type representing a sequence of bytes.

Notes

Some databases treat strings and blobs of equally, and some do not.

For example, Impala doesn't make a distinction between string and binary types but PostgreSQL has a TEXT type and a BYTEA type which are distinct types that have different behavior.

Boolean

Bases: Primitive

True or False values.

Bounds

Bases: NamedTuple

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

DataType

Bases: Concrete, Coercible

Base class for all data types.

DataType instances are immutable.

Attributes
name: str property

Return the name of the data type.

Functions
from_dask(dask_type, nullable=True) classmethod

Return the equivalent ibis datatype.

from_numpy(numpy_type, nullable=True) classmethod

Return the equivalent ibis datatype.

from_pandas(pandas_type, nullable=True) classmethod

Return the equivalent ibis datatype.

from_pyarrow(arrow_type, nullable=True) classmethod

Return the equivalent ibis datatype.

is_array()

Return True if an instance of an Array type.

is_binary()

Return True if an instance of a Binary type.

is_boolean()

Return True if an instance of a Boolean type.

is_date()

Return True if an instance of a Date type.

is_decimal()

Return True if an instance of a Decimal type.

is_enum()

Return True if an instance of an Enum type.

is_float16()

Return True if an instance of a Float16 type.

is_float32()

Return True if an instance of a Float32 type.

is_float64()

Return True if an instance of a Float64 type.

is_floating()

Return True if an instance of any Floating type.

is_geospatial()

Return True if an instance of a Geospatial type.

is_inet()

Return True if an instance of an Inet type.

is_int16()

Return True if an instance of an Int16 type.

is_int32()

Return True if an instance of an Int32 type.

is_int64()

Return True if an instance of an Int64 type.

is_int8()

Return True if an instance of an Int8 type.

is_integer()

Return True if an instance of any Integer type.

is_interval()

Return True if an instance of an Interval type.

is_json()

Return True if an instance of a JSON type.

is_linestring()

Return True if an instance of a LineString type.

is_macaddr()

Return True if an instance of a MACADDR type.

is_map()

Return True if an instance of a Map type.

is_multilinestring()

Return True if an instance of a MultiLineString type.

is_multipoint()

Return True if an instance of a MultiPoint type.

is_multipolygon()

Return True if an instance of a MultiPolygon type.

is_nested()

Return true if an instance of any nested (Array/Map/Struct) type.

is_null()

Return true if an instance of a Null type.

is_numeric()

Return true if an instance of a Numeric type.

is_point()

Return true if an instance of a Point type.

is_polygon()

Return true if an instance of a Polygon type.

is_primitive()

Return true if an instance of a Primitive type.

is_signed_integer()

Return true if an instance of a SignedInteger type.

is_string()

Return true if an instance of a String type.

is_struct()

Return true if an instance of a Struct type.

is_temporal()

Return true if an instance of a Temporal type.

is_time()

Return true if an instance of a Time type.

is_timestamp()

Return true if an instance of a Timestamp type.

is_uint16()

Return true if an instance of a UInt16 type.

is_uint32()

Return true if an instance of a UInt32 type.

is_uint64()

Return true if an instance of a UInt64 type.

is_uint8()

Return true if an instance of a UInt8 type.

is_unknown()

Return true if an instance of an Unknown type.

is_unsigned_integer()

Return true if an instance of an UnsignedInteger type.

is_uuid()

Return true if an instance of a UUID type.

is_variadic()

Return true if an instance of a Variadic type.

to_dask()

Return the equivalent dask datatype.

to_numpy()

Return the equivalent numpy datatype.

to_pandas()

Return the equivalent pandas datatype.

to_pyarrow()

Return the equivalent pyarrow datatype.

Date

Bases: Temporal, Primitive

Date values.

Decimal

Bases: Numeric, Parametric

Fixed-precision decimal values.

Attributes
largest property

Return the largest type of decimal.

precision: Optional[int] = None class-attribute instance-attribute

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

scale: Optional[int] = None class-attribute instance-attribute

The number of values after the decimal point.

Float16

Bases: Floating

16-bit floating point numbers.

Float32

Bases: Floating

32-bit floating point numbers.

Float64

Bases: Floating

64-bit floating point numbers.

Floating

Bases: Primitive, Numeric

Floating point values.

Attributes
largest property

Return the largest type of floating point values.

GeoSpatial

Bases: DataType

Geospatial values.

Attributes
geotype: Optional[Literal['geography', 'geometry']] = None class-attribute instance-attribute

The specific geospatial type.

srid: Optional[int] = None class-attribute instance-attribute

The spatial reference identifier.

INET

Bases: String

IP addresses.

Int16

Bases: SignedInteger

Signed 16-bit integers.

Int32

Bases: SignedInteger

Signed 32-bit integers.

Int64

Bases: SignedInteger

Signed 64-bit integers.

Int8

Bases: SignedInteger

Signed 8-bit integers.

Integer

Bases: Primitive, Numeric

Integer values.

Attributes
nbytes: int abstractmethod property

Return the number of bytes used to store values of this type.

Interval

Bases: Parametric

Interval values.

Attributes
resolution property

The interval unit's name.

unit: IntervalUnit instance-attribute

The time unit of the interval.

JSON

Bases: Variadic

JSON values.

LineString

Bases: GeoSpatial

A sequence of 2 or more points.

MACADDR

Bases: String

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

Map

Bases: Variadic, Parametric

Associative array values.

MultiLineString

Bases: GeoSpatial

A set of one or more line strings.

MultiPoint

Bases: GeoSpatial

A set of one or more points.

MultiPolygon

Bases: GeoSpatial

A set of one or more polygons.

Null

Bases: Primitive

Null values.

Numeric

Bases: DataType

Numeric types.

Parametric

Bases: DataType

Types that can be parameterized.

Point

Bases: GeoSpatial

A point described by two coordinates.

Polygon

Bases: 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

Bases: DataType, Singleton

Values with known size.

SignedInteger

Bases: Integer

Signed integer values.

Attributes
largest property

Return the largest type of signed integer.

String

Bases: Variadic, Singleton

A type representing a string.

Notes

Because of differences in the way different backends handle strings, we cannot assume that strings are UTF-8 encoded.

Struct

Bases: Parametric, MapSet

Structured values.

Functions
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
nullable bool

Whether the type is nullable

True

Returns:

Type Description
Struct

Struct data type instance

names()

Return the names of the struct's fields.

types()

Return the types of the struct's fields.

Temporal

Bases: DataType

Data types related to time.

Time

Bases: Temporal, Primitive

Time values.

Timestamp

Bases: Temporal, Parametric

Timestamp values.

Attributes
scale: Optional[Literal[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]] = None class-attribute instance-attribute

The scale of the timestamp if known.

timezone: Optional[str] = None class-attribute instance-attribute

The timezone of values of this type.

unit: str property

Return the unit of the timestamp.

Functions
from_unit(unit, timezone=None, nullable=True) classmethod

Return a timestamp type with the given unit and timezone.

UInt16

Bases: UnsignedInteger

Unsigned 16-bit integers.

UInt32

Bases: UnsignedInteger

Unsigned 32-bit integers.

UInt64

Bases: UnsignedInteger

Unsigned 64-bit integers.

UInt8

Bases: UnsignedInteger

Unsigned 8-bit integers.

UUID

Bases: DataType

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

Unknown

Bases: DataType, Singleton

An unknown type.

UnsignedInteger

Bases: Integer

Unsigned integer values.

Attributes
largest property

Return the largest type of unsigned integer.

Variadic

Bases: DataType

Values with unknown size.

Functions

dtype(value, nullable=True)

Create a DataType object.

Parameters:

Name Type Description Default
value Any

The object to coerce to an Ibis DataType. Supported inputs include strings, python type annotations, numpy dtypes, pandas dtypes, and pyarrow types.

required
nullable bool

Whether the type should be nullable. Defaults to True.

True

Examples:

>>> import ibis
>>> ibis.dtype("int32")
Int32(nullable=True)
>>> ibis.dtype("array<float>")
Array(value_type=Float64(nullable=True), nullable=True)

DataType objects may also be created from Python types:

>>> ibis.dtype(int)
Int64(nullable=True)
>>> ibis.dtype(list[float])
Array(value_type=Float64(nullable=True), nullable=True)

Or other type systems, like numpy/pandas/pyarrow types:

>>> import pyarrow as pa
>>> ibis.dtype(pa.int32())
Int32(nullable=True)

Last update: June 22, 2023