Uploaded image for project: 'Apache Arrow'
  1. Apache Arrow
  2. ARROW-5905

[Python] support conversion to decimal type from floats?

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Open
    • Major
    • Resolution: Unresolved
    • None
    • None
    • Python
    • None

    Description

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

      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
      ]
      

      but not from floats (or strings):

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

      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.

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              jorisvandenbossche Joris Van den Bossche
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated: