aad1tyaaaaa opened a new pull request, #1047:
URL: https://github.com/apache/arrow-nanoarrow/pull/1047
Closes #1040.
The C library supports `DECIMAL32` and `DECIMAL64`, but the Python bindings
did not, so `iter_py()` raised `KeyError: "Can't resolve iterator for type
'decimal32'"` and there was no way to create these types from Python. This PR
adds:
- `na.Type.DECIMAL32` / `na.Type.DECIMAL64` and the `na.decimal32()` /
`na.decimal64()` constructors, with `precision` and `scale` like the existing
decimal types
- iteration through the existing `_decimal_iter`
As suggested in the issue, the buffer formats are the signed 32-bit and
64-bit integer codes (`"i"` and `"q"`), not fixed-size binary. These buffers
then use the fast memoryview path and give `int` values directly, so
`_decimal_iter` only converts from bytes for the 128- and 256-bit types.
One side effect: `na.c_buffer([...], na.decimal32(...))` builds its buffer
through `array.array("i", ...)`, so the resulting buffer reports `data_type ==
"int32"`. `interval_months` already does the same thing today, so I left it
alone. I can special-case it if you'd prefer.
Tests cover iteration against pyarrow (nulls, negative values, slices,
scales -2/0/2/precision, and maximum precision 9 and 18), the schema
constructors, the schema view accessors (including a negative scale), and
buffers built from Python ints. The new tests fail on `main` and pass with this
change; the full Python test suite passes, and black and flake8 are clean.
I used an AI assistant (Claude Code) to help write this change and the
tests. I reviewed and ran everything myself.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]