pyarrow.decimal128#

pyarrow.decimal128(int precision, int scale=0) DataType#

Create decimal type with precision and scale and 128-bit width.

Arrow decimals are fixed-point decimal numbers encoded as a scaled integer. The precision is the number of significant digits that the decimal type can represent; the scale is the number of digits after the decimal point (note the scale can be negative).

As an example, decimal128(7, 3) can exactly represent the numbers 1234.567 and -1234.567 (encoded internally as the 128-bit integers 1234567 and -1234567, respectively), but neither 12345.67 nor 123.4567.

decimal128(5, -3) can exactly represent the number 12345000 (encoded internally as the 128-bit integer 12345), but neither 123450000 nor 1234500.

If you need a precision higher than 38 significant digits, consider using decimal256.

Parameters:
precisionint

Must be between 1 and 38

scaleint
Returns:
decimal_typeDecimal128Type

Examples

Create an instance of decimal type:

>>> import pyarrow as pa
>>> pa.decimal128(5, 2)
Decimal128Type(decimal128(5, 2))

Create an array with decimal type:

>>> import decimal
>>> a = decimal.Decimal('123.45')
>>> pa.array([a], pa.decimal128(5, 2))
<pyarrow.lib.Decimal128Array object at ...>
[
  123.45
]