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

[Python] __arrow_array__ does not work for ExtensionTypes in Table.from_pandas

    XMLWordPrintableJSON

    Details

      Description

      When someone has a custom ExtensionType defined in Python, and an array class that gets converted to that (through __arrow_array__), the conversion in pyarrow works with the array class, but not yet for the array stored in a pandas DataFrame.

      Eg using my definition of ArrowPeriodType in https://github.com/pandas-dev/pandas/pull/28371, I see:

      In [15]: pd_array = pd.period_range("2012-01-01", periods=3, freq="D").array                                                                                                                                       
      
      In [16]: pd_array                                                                                                                                                                                                  
      Out[16]: 
      <PeriodArray>
      ['2012-01-01', '2012-01-02', '2012-01-03']
      Length: 3, dtype: period[D]
      
      In [17]: pa.array(pd_array)                                                                                                                                                                                        
      Out[17]: 
      <pyarrow.lib.ExtensionArray object at 0x7f657cf78768>
      [
        15340,
        15341,
        15342
      ]
      
      In [18]: df = pd.DataFrame({'periods': pd_array})                                                                                                                                                                  
      
      In [19]: pa.table(df)                                                                                                                                                                                              
      ...
      ArrowInvalid: ('Could not convert 2012-01-01 with type Period: did not recognize Python value type when inferring an Arrow data type', 'Conversion failed for column periods with type period[D]')
      

      (this is working correctly for array objects whose __arrow_array__ is returning a built-in pyarrow Array).

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                jorisvandenbossche Joris Van den Bossche
                Reporter:
                jorisvandenbossche Joris Van den Bossche
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 1h
                  1h