CameronBieganek opened a new issue, #38019:
URL: https://github.com/apache/arrow/issues/38019

   ### Describe the bug, including details regarding any error messages, 
version, and platform.
   
   Trying to create a scalar or array of type `pa.decimal128(4, 2)` fails:
   
   ```python
   In [90]: pa.scalar(1.2, type=pa.decimal128(4, 2))
   ---------------------------------------------------------------------------
   ArrowTypeError                            Traceback (most recent call last)
   Cell In[90], line 1
   ----> 1 pa.scalar(1.2, type=pa.decimal128(4, 2))
   
   File 
~\projects\ML_App_Template\venv\Lib\site-packages\pyarrow\scalar.pxi:1122, in 
pyarrow.lib.scalar()
   
   File 
~\projects\ML_App_Template\venv\Lib\site-packages\pyarrow\error.pxi:144, in 
pyarrow.lib.pyarrow_internal_check_status()
   
   File 
~\projects\ML_App_Template\venv\Lib\site-packages\pyarrow\error.pxi:123, in 
pyarrow.lib.check_status()
   
   ArrowTypeError: int or Decimal object expected, got float
   
   In [91]: pa.array([1.2, 3.4], type=pa.decimal128(4, 2))
   ---------------------------------------------------------------------------
   ArrowTypeError                            Traceback (most recent call last)
   Cell In[91], line 1
   ----> 1 pa.array([1.2, 3.4], type=pa.decimal128(4, 2))
   
   File 
~\projects\ML_App_Template\venv\Lib\site-packages\pyarrow\array.pxi:327, in 
pyarrow.lib.array()
   
   File ~\projects\ML_App_Template\venv\Lib\site-packages\pyarrow\array.pxi:39, 
in pyarrow.lib._sequence_to_array()
   
   File 
~\projects\ML_App_Template\venv\Lib\site-packages\pyarrow\error.pxi:144, in 
pyarrow.lib.pyarrow_internal_check_status()
   
   File 
~\projects\ML_App_Template\venv\Lib\site-packages\pyarrow\error.pxi:123, in 
pyarrow.lib.check_status()
   
   ArrowTypeError: int or Decimal object expected, got float
   ```
   
   But creating a float array and then casting to `pa.decimal128` does work:
   
   ```python
   In [92]: pa.scalar(1.2).cast(pa.decimal128(4, 2))
   Out[92]: <pyarrow.Decimal128Scalar: Decimal('1.20')>
   
   In [93]: pa.array([1.2, 3.4]).cast(pa.decimal128(4, 2))
   Out[93]:
   <pyarrow.lib.Decimal128Array object at 0x0000023334EAF1C0>
   [
     1.20,
     3.40
   ]
   ```
   
   Can the direct construction (without `cast`) be made to work? I couldn't 
find any documentation on other ways to create a decimal, like 
`Decimal('1.20')`. I've seen `Decimal('1.20')` used in a different github 
issue, but I can't figure out which module `Decimal` is in (if it still exists).
   
   ```python
   In [94]: pa.__version__
   Out[94]: '13.0.0'
   ```
   
   ### Component(s)
   
   Python


-- 
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]

Reply via email to