apache / arrow

Apache Arrow is the universal columnar format and multi-language toolbox for fast data interchange and in-memory analytics
https://arrow.apache.org/
Apache License 2.0
14.63k stars 3.56k forks source link

Behavior of decimal array construction with numpy int64 arrays fails, but a list of ints works #44712

Open cpcloud opened 1 week ago

cpcloud commented 1 week ago

Describe the bug, including details regarding any error messages, version, and platform.

This is using PyArrow 18.0.0.

It looks like passing an array of int64 fails when trying to use that as input for constructing a decimal128 array, while using a Python list of int successfully constructs the array.

Reproducible example:

In [52]: import pyarrow as pa

In [53]: import numpy as np

In [54]: pa.array(np.array([1]), pa.decimal128(38, 9))
╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│ in <module>:1                                                                                    │
│                                                                                                  │
│ in pyarrow.lib.array:360                                                                         │
│                                                                                                  │
│ in pyarrow.lib._ndarray_to_array:87                                                              │
│                                                                                                  │
│ in pyarrow.lib.check_status:92                                                                   │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
ArrowInvalid: Got bytestring of length 8 (expected 16)

In [55]: pa.array([1], pa.decimal128(38, 9))
Out[55]:
<pyarrow.lib.Decimal128Array object at 0x7f0ccef07040>
[
  1.000000000
]

Component(s)

Python