Skip to content

Add Arrow Decimal Array Support - #189

Merged
pbower merged 10 commits into
mainfrom
feature/decimal
Aug 31, 2026
Merged

Add Arrow Decimal Array Support#189
pbower merged 10 commits into
mainfrom
feature/decimal

Conversation

@pbower

@pbower pbower commented Aug 31, 2026

Copy link
Copy Markdown
Collaborator

Add Decimal32, Decimal64, and Decimal128 array support

This feature adds fixed-point Arrow-compliant decimal arrays for exact numeric values where floating-point approximation is not acceptable (for e.g., monetary, accounting, and high-precision numeric columns).

  • DecimalArray struct generic over i32/i64/i128 with precision and scale metadata
  • Integration across NumericArray, Array, Scalar, Value, Views, SuperArray, and Consolidate
  • Arrow C Data Interface import/export with format string round-trips for all three widths
  • arrow-rs and Polars bridge round-trips
  • Arithmetic kernels with checked overflow, scale reconciliation, and auto-promotion
  • Type conversions between decimal and integer/float types, plus width widening and narrowing
  • Broadcasting and scale-aware print formatting
  • pyo3 zero-copy bridge and minarrow-py pure-Python construction/inspection
  • Gated behind #[cfg(feature = "decimal")] without impacting builds that don't have the feature

pbower added 9 commits August 31, 2026 02:57
)

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

Phase 2 of EPC86. Adds Decimal32/64/128 variants gated behind
the `decimal` feature flag to NumericArray, Array, and Scalar enums.
Cascades match arms across all dispatch sites, adds typed accessors
(dec32/try_dec32, dec64/try_dec64, dec128/try_dec128), widening
conversions between decimal widths, and liberal From impls for
DecimalArray -> NumericArray -> Array.

* Implement decimal conversion arms in NumericArray try_ accessors

The try_i32/i64/u32/u64/f32/f64/bool/str methods and cow_into_f64
previously returned errors for decimal variants. Now they perform
scale-aware conversions consistent with every other numeric type.
)

* Add decimal FFI import/export with arrow-rs and Polars round-trips
… SuperArrayV, and Consolidate (#187)

- Add DecimalAVT type alias for decimal view tuples
- Add Consolidate impl for Vec<DecimalAVT> with precision/scale propagation
- Wire gather_decimal! macro in Vec<ArrayVT> consolidation (replaces panics)
- Add Decimal32/64/128 arms to Array::inner, inner_mut, inner_check, inner_check_mut
- Import DecimalArray in array.rs for the inner method type resolution
- Tests for ArrayV windowing, NumericArrayV decimal views, SuperArray chunked
  append with type validation, SuperArrayV consolidation across chunks,
  null mask propagation, and Value flow-through
…on + 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 Decimal32 and Decimal64 round-trip tests for arrow-rs

Polars only supports i128-backed decimals so Decimal32/64 round-trips
are not valid through that path without widening first.

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

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

* Make precision and scale report values for all numeric types

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 changed the title Add Decimal Types Add Arrow Decimal Array Support Aug 31, 2026
@pbower
pbower merged commit 7801a3d into main Aug 31, 2026
17 checks passed
@pbower
pbower deleted the feature/decimal branch August 31, 2026 08:11
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