Skip to content

[Python] ExtensionArray.to_pandas not working #26798

Closed

Description

@asfimport

Hi!

When I create a pandas interval series and then convert it into a pyarrow array and then try to convert that pyarrow array back to pandas I'm getting an attribute error. The error says that Series object has no attribute to_pandas.

I've added the code that produces the error below. 

// code placeholder

In [14]: x = pd.Series([pd.Interval(0, 1), pd.Interval(2, 3), pd.Interval(3, 4)])

In [15]: y = pa.Array.from_pandas(x)

In [16]: y.type
Out[17]: ArrowIntervalType(extension<pandas.interval>)

In [17]: y.to_pandas()
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-17-48c5b189df56> in <module>
----> 1 y.to_pandas()~/compose/etc/conda/cuda_10.2/envs/rapids/lib/python3.7/site-packages/pyarrow/array.pxi in pyarrow.lib._PandasConvertible.to_pandas()~/compose/etc/conda/cuda_10.2/envs/rapids/lib/python3.7/site-packages/pyarrow/array.pxi in pyarrow.lib.ExtensionArray._to_pandas()~/compose/etc/conda/cuda_10.2/envs/rapids/lib/python3.7/site-packages/pandas/core/generic.py in __getattr__(self, name)
   5128             if self._info_axis._can_hold_identifiers_and_holds_name(name):
   5129                 return self[name]
-> 5130             return object.__getattribute__(self, name)
   5131 
   5132     def __setattr__(self, name: str, value) -> None:AttributeError: 'Series' object has no attribute 'to_pandas'

It would be great tp have a method to convert from a pyarrow interval array directly into a pandas series. 

Reporter: Marlene Mhangami
Assignee: Joris Van den Bossche / @jorisvandenbossche

PRs and other links:

Note: This issue was originally created as ARROW-10863. Please see the migration documentation for further details.

Activity

  1. asfimport commented on Dec 10, 2020

    @asfimport
    Author

    Joris Van den Bossche / @jorisvandenbossche:
    [~marlene_zw] thanks for the report!
    This was clearly not tested, as the to_pandas method in general doesn't seem to be working for any ExtensionType (so not just for the pandas interval type). Will take a look at it.

  2. asfimport commented on Dec 10, 2020

    @asfimport
    Author

    Marlene Mhangami:
    Awesome @jorisvandenbossche! Glad it was helpful :D 

  3. asfimport commented on Dec 15, 2020

    @asfimport
    Author

    Antoine Pitrou / @pitrou:
    Issue resolved by pull request 8887
    #8887

  4. added this to the 3.0.0 milestone on Jan 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions