Skip to content

Add decimal support to pyo3 and minarrow-py Python bridges - #188

Merged
pbower merged 3 commits into
feature/decimalfrom
MA-EPC86-DECIMAL-TSK383-PYTHON
Aug 31, 2026
Merged

Add decimal support to pyo3 and minarrow-py Python bridges#188
pbower merged 3 commits into
feature/decimalfrom
MA-EPC86-DECIMAL-TSK383-PYTHON

Conversation

@pbower

@pbower pbower commented Aug 31, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • pyo3: Decimal32/64/128 map to PyArrow pa.decimal128() for export/import via the existing Arrow C Data Interface FFI.
  • minarrow-py: construction from list[int] via dtype="decimal128(P,S)", element access returns decimal.Decimal, scale-aware repr, .precision and .scale properties
  • Adds Decimal32 and Decimal64 round-trip tests for arrow-rs C Data Interface (gap from TSK378 which only tested Decimal128)
  • 26 new tests across pyo3 and minarrow-py

Test plan

  • pyo3 pytest passes (23 tests including 3 new decimal)
  • minarrow-py pytest passes (139 tests including 23 new decimal)
  • cargo test --features "decimal,cast_arrow" passes (all three widths round-trip)
  • cargo test --features decimal passes

pbower added 2 commits August 31, 2026 08:05
Polars only supports i128-backed decimals so Decimal32/64 round-trips
are not valid through that path without widening first.
pyo3:
- Add `decimal` feature flag forwarding minarrow/decimal
- Map Decimal32/64/128 ArrowType variants to pa.decimal128() in
  arrow_type_to_pyarrow (PyArrow only supports 128-bit decimal)
- Zero-copy export/import through existing Arrow C Data Interface FFI
- Document decimal type mappings in the FFI module
- Add Decimal128 roundtrip tests (array, high precision, RecordBatch)

minarrow-py:
- Add `decimal` feature flag
- Add Decimal32/64/128 variants to PyArrowType enum with From impls
- Add DType::Decimal variant with Numeric group membership
- Add precision/scale properties on PyArray (None for non-decimal)
- Handle decimal dtype strings: decimal128(P,S), decimal64(P,S),
  decimal32(P,S), decimal(P,S) alias for Decimal128
- Construct DecimalArray from Python int sequences with dtype param
- Return Python decimal.Decimal values from element access
- Scale-aware formatting in repr via format_decimal_string
- 23 pytest tests covering construction, inspection, element access,
  display, slicing, ArrowType, and PyArrow round-trip
@pbower pbower changed the title Add decimal support to pyo3 and minarrow-py Python bridges (TSK383) Add decimal support to pyo3 and minarrow-py Python bridges Aug 31, 2026
@pbower
pbower force-pushed the MA-EPC86-DECIMAL-TSK383-PYTHON branch 3 times, most recently from 7c2e955 to fed0ca2 Compare August 31, 2026 07:43
Precision and scale are properties of numeric data, not decimal-specific.
Integer types report their digit capacity with scale 0, float types
report their significant-digit capacity, and decimal types report
their configured precision and scale.
@pbower
pbower force-pushed the MA-EPC86-DECIMAL-TSK383-PYTHON branch from fed0ca2 to 3b82851 Compare August 31, 2026 07:46
@pbower
pbower merged commit 040e865 into feature/decimal Aug 31, 2026
14 of 17 checks passed
@pbower
pbower deleted the MA-EPC86-DECIMAL-TSK383-PYTHON branch August 31, 2026 07:47
pbower added a commit that referenced this pull request Aug 31, 2026
* Add DecimalArray foundation and i128 trait impls (#181)

* Add Decimal32, Decimal64, Decimal128 variants to ArrowType (#180)

* Wire DecimalArray into NumericArray, Array, Scalar with From impls (#182)

* Wire DecimalArray into NumericArray, Array, and Scalar enums with From impls and tests (#182)

* Implement decimal conversion arms in NumericArray try_ accessors

* Add decimal FFI import/export with arrow-rs and Polars round-trips (#186)

* Add decimal FFI import/export with arrow-rs and Polars round-trips

* Integrate DecimalArray into Value, ArrayV, NumericArrayV, SuperArray, SuperArrayV, and Consolidate (#187)

* Add decimal broadcast dispatch and scale-aware print formatting (#184)

* Add decimal arithmetic kernels with checked overflow and auto-promotion + fix null mask drop on broadcasting (#185)

* Add decimal arithmetic kernels with checked overflow and auto-promotion
* Propagate null mask through broadcast for all array types

* Add DecimalArray type conversions and width conversion methods (#183)

* Add decimal support to pyo3 and minarrow-py Python bridges (#188)

* Add Decimal32 and Decimal64 round-trip tests for arrow-rs

* Add decimal support to pyo3 and minarrow-py Python bridges

* Make precision and scale report values for all numeric types
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant