Dear Arrow team and users, I have a simple question regarding the decimal data 
type with pyarrow. I am trying to cast a table with decimal columns to string, 
or to write it to a csv file. In both cases I get the error message:

    pyarrow.lib.ArrowNotImplementedError: Unsupported cast from decimal128(18, 
9) to utf8 using function cast_string

I understand that is not implemented yet, but is there by chance a way to get 
around this?
Thanks, François.

PS: I am using Python : 3.9.13 & pyarrow : 8.0.0
Here is a code snippet:

import decimal

import pyarrow as pa
import pyarrow.compute as pc
import pyarrow.csv

PREC, SCAL = 18, 9  # decimal precision & scale

context = decimal.getcontext()
context.prec = PREC
ref_decimal = decimal.Decimal('0.123456789')

float_numbers = [0.1, 654.5, 4.65742]
decimal_numbers = [
    decimal.Decimal(str(f)).quantize(ref_decimal) for f in float_numbers
]

pa_arr_dec = pa.array(
    decimal_numbers, type=pa.decimal128(precision=PREC, scale=SCAL)
)
pa_arr_str = pc.cast(pa_arr_dec, pa.string())


  Traceback (most recent call last):
    File "/home/francois/Workspace/.../scripts/pyarrow_decimal.py", line 21, in 
<module>
      pa_arr_str = pc.cast(pa_arr_dec, pa.string())
    File 
"/home/francois/miniconda3/envs/tableau2/lib/python3.9/site-packages/pyarrow/compute.py",
 line 376, in cast
      return call_function("cast", [arr], options)
    File "pyarrow/_compute.pyx", line 542, in pyarrow._compute.call_function
    File "pyarrow/_compute.pyx", line 341, in pyarrow._compute.Function.call
    File "pyarrow/error.pxi", line 144, in 
pyarrow.lib.pyarrow_internal_check_status
    File "pyarrow/error.pxi", line 121, in pyarrow.lib.check_status
  pyarrow.lib.ArrowNotImplementedError: Unsupported cast from decimal128(18, 9) 
to utf8 using function cast_string

Reply via email to