Skip to content

ARROW-10863: [Python] Fix ExtensionArray.to_pandas to use underlying storage array - #8887

Closed
jorisvandenbossche wants to merge 2 commits into
apache:masterfrom
jorisvandenbossche:ARROW-10863-ext-to-pandas
Closed

jorisvandenbossche wants to merge 2 commits into
apache:masterfrom
jorisvandenbossche:ARROW-10863-ext-to-pandas

Conversation

@jorisvandenbossche

Copy link
Copy Markdown
Member

No description provided.

@github-actions

Copy link
Copy Markdown

@pitrou

pitrou commented Dec 14, 2020

Copy link
Copy Markdown
Member

The report is for a Series of intervals. Can we add a test case for that? (will it roundtrip faithfully?)

@jorisvandenbossche

Copy link
Copy Markdown
Member Author

It does not yet roundtrip faithfully (it comes back as object array with dicts, as its storage type is a StructArray), because we currently only support pandas' extension types in the Table.to_pandas conversion, and not yet in the Array/ChunkedArray to_pandas conversions (eg partly covered by https://issues.apache.org/jira/browse/ARROW-9664).

We are testing specific pandas dtypes in test_pandas.py, but so only for table.

@pitrou

pitrou commented Dec 14, 2020

Copy link
Copy Markdown
Member

It would be nice to add a test in any case, even if it's only testing the less-than-ideal return type.

@jorisvandenbossche

Copy link
Copy Markdown
Member Author

In the end, wasn't that difficult to directly fix the full roundtrip as well, so did that + add a test for the original report.

@pitrou pitrou left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you @jorisvandenbossche

@pitrou pitrou closed this in 7fa25fe Dec 15, 2020
@kou

kou commented Dec 16, 2020

Copy link
Copy Markdown
Member

@github-actions crossbow submit wheel-manylinux2014-cp36m

@github-actions

Copy link
Copy Markdown

Revision: cded64c

Submitted crossbow builds: ursa-labs/crossbow @ actions-796

Task Status
wheel-manylinux2014-cp36m Azure

# TODO implement proper conversion for chunked array
# result = pa.table({"col": arr})["col"].to_pandas()
# expected = pd.Series(arr, name="col")
# tm.assert_series_equal(result, expected)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is failed on wheel-manylinux*-cp{36,37}*:

https://dev.azure.com/ursa-labs/crossbow/_build/results?buildId=21715&view=logs&j=0da5d1d9-276d-5173-c4c4-9d4d4ed14fdb&t=3367cfe7-6aa5-5a88-c888-e6814d74f6eb&l=176

    def test_array_to_pandas():
        if LooseVersion(pd.__version__) < "1.0":
            pytest.skip("ExtensionDtype __from_arrow__ protocol missing")
    
        for arr in [pd.period_range("2012-01-01", periods=3, freq="D").array,
                    pd.interval_range(1, 4).array]:
            result = pa.array(arr).to_pandas()
            expected = pd.Series(arr)
>           tm.assert_series_equal(result, expected)
E           AssertionError: Attributes of Series are different
E           
E           Attribute "dtype" are different
E           [left]:  int64
E           [right]: period[D]

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, maybe my skip for pandas was wrong. Is there any way to see which pandas version is being used in that wheel build? (based on the requirements-wheel-test.txt file I would assume the latest, but I don't see it anywhere in the output)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In any case, the feature was only added in pandas 1.1, not 1.0, so the skip I added was wrong. Fixing that in #8934

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants