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

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

Base class for all data types.

DataType instances are immutable.

Attributes
name: str property

Return the name of the data type.

Functions
to_pandas()

Return the equivalent pandas datatype.

to_pyarrow()

Return the equivalent pyarrow datatype.

Date

Bases: Temporal, Primitive

Date values.

Decimal

Bases: Numeric

Fixed-precision decimal values.

Attributes
largest property

Return the largest type of decimal.

precision = optional(instance_of(int)) class-attribute

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

scale = optional(instance_of(int)) class-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(isin({'geography', 'geometry'})) class-attribute

The specific geospatial type.

srid = optional(instance_of(int)) class-attribute

The spatial reference identifier.

Geography

Bases: GeoSpatial

Geography values.

Geometry

Bases: GeoSpatial

Geometry values.

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.

Interval

Bases: DataType

Interval values.

Attributes
resolution property

The interval unit's name.

unit = optional(map_to(__valid_units__), default='s') class-attribute

The time unit of the interval.

value_type = optional(all_of([datatype, instance_of(Integer)]), default=Int32()) class-attribute

The underlying type of the stored values.

JSON

Bases: String

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

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.

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.

Set

Bases: Variadic

Set values.

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

Structured values.

Attributes
pairs: Mapping[str, DataType] property

Return a mapping from names to data type instances.

Returns:

Type Description
Mapping[str, DataType]

Mapping of field name to data type

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

Whether the type is nullable

True

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

Whether the type is nullable

True

Returns:

Type Description
Struct

Struct data type instance

Temporal

Bases: DataType

Data types related to time.

Time

Bases: Temporal, Primitive

Time values.

Timestamp

Bases: Temporal

Timestamp values.

Attributes
timezone = optional(instance_of(str)) class-attribute

The timezone of values of this type.

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.

UnsignedInteger

Bases: Integer

Unsigned integer values.

Attributes
largest property

Return the largest type of unsigned integer.

Variadic

Bases: DataType

Values with unknown size.

Functions


Last update: August 5, 2022