Dtype#

Data types control how bits are converted into values, and how values are converted into bits.

They are often used implicitly when creating from or interpreting to integers, floats and other types, but can also be used explicitly in methods like Tibs.from_values().

class Dtype(self, spec, /)#

A data type which determines how a value is encoded as a fixed-width bit sequence.

Dtype is used by Tibs.from_value(), Tibs.to_value(), Tibs.from_values() and related methods to describe the kind, length and optional byte order for encoded values.

>>> Dtype("u16_le")
Dtype('u16_le')
>>> Tibs.from_value("u8", 15)
Tibs('0x0f')
from_params(kind, length, byte_order)#

Create a dtype from explicit parameters.

Parameters:
  • kind (DtypeKind) – The kind of value to encode or decode.

  • length (int) – The number of bits used by one value.

  • byte_order (Endianness) – The byte order for integer and floating-point values. Defaults to Endianness.Unspecified.

Returns:

A new Dtype.

Raises:

ValueError – if length is not greater than zero, if byte order is used with a non-numeric kind, or if byte order is used with a non-byte length.

>>> Dtype.from_params(DtypeKind.Uint, 16, Endianness.Little)
Dtype('u16_le')
byte_order#

The byte order used by integer and floating-point values.

kind#

The value kind described by this dtype.

length#

The number of bits used by one value.