You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@arrow.apache.org by "Joris Van den Bossche (JIRA)" <ji...@apache.org> on 2019/07/10 22:27:00 UTC

[jira] [Created] (ARROW-5905) [Python] support conversion to decimal type from floats?

Joris Van den Bossche created ARROW-5905:
--------------------------------------------

             Summary: [Python] support conversion to decimal type from floats?
                 Key: ARROW-5905
                 URL: https://issues.apache.org/jira/browse/ARROW-5905
             Project: Apache Arrow
          Issue Type: Improvement
          Components: Python
            Reporter: Joris Van den Bossche


We currently allow constructing a decimal array from decimal.Decimal objects or from ints:

{code}
In [14]: pa.array([1, 0], type=pa.decimal128(2))                                                                                                              
Out[14]: 
<pyarrow.lib.Decimal128Array object at 0x7f51fa2da818>
[
  1,
  0
]

In [31]: pa.array([decimal.Decimal('0.1'), decimal.Decimal('0.2')], pa.decimal128(2, 1))                                                                      
Out[31]: 
<pyarrow.lib.Decimal128Array object at 0x7fce671172b0>
[
  0.1,
  0.2
]
{code}

but not from floats (or strings):

{code}
In [18]: pa.array([0.1, 0.2], pa.decimal128(2))                                                                                                               
...
ArrowTypeError: int or Decimal object expected, got float
{code}

Is this something we would like to support?

There are for sure precision issues you run into, but if the decimal type is fully specified, it seems clear what the user wants. In general, since decimal objects in pandas are not that easy to work with, many people might have plain float columns that they want to convert to decimal. 



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)