pyarrow.decimal128#

pyarrow.decimal128(intprecision,intscale=0)DataType#

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

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

As an example,decimal128(7,3) can exactly represent the numbers1234.567 and -1234.567 (encoded internally as the 128-bit integers1234567 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 neither123450000 nor 1234500.

If you need a precision higher than 38 significant digits, considerusingdecimal256.

Parameters:
precisionint

Must be between 1 and 38

scaleint
Returns:
decimal_typeDecimal128Type

Examples

Create an instance of decimal type:

>>>importpyarrowaspa>>>pa.decimal128(5,2)Decimal128Type(decimal128(5, 2))

Create an array with decimal type:

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