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

[Python] pa.array.to_pandas(types_mapper=...) doesn't change the dtype

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Duplicate
    • 1.0.0
    • None
    • Python
    • None

    Description

      Hello !

      It looks like it is possible to map arrow types to pandas types using the `types_mapper` argument in `to_pandas`. However it seems to work only for `pa.Table.to_pandas` and not `pa.array.to_pandas`.

      Example to reproduce:

      import pyarrow as pa
      import pandas as pd
      
      def types_mapper(dtype):
          print("Looking at dtype")
          if dtype == pa.int64():
              print("Changing dtype")
              return pd.Int32Dtype()
      
      arr = pa.array([1,2,3], pa.int64())
      
      print(pa.Table.from_arrays([arr], names=["col"]).to_pandas(types_mapper=types_mapper).col.dtype)
      # Prints:
      # Looking at dtype
      # Changing dtype
      # Int32
      
      print(arr.to_pandas(types_mapper=types_mapper).dtype)
      # Prints:
      # int64
      

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              lhoestq quentin lhoest
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Slack

                  Issue deployment