Skip to content

BUG: DataFrame.to_dict(orient="records") does not return native types with frame constructed from pyarrow Scalars #37642

Open
@arw2019

Description

@arw2019

On 1.2 master:

In [15]: import pandas as pd
    ...: import pyarrow as pa
    ...: 
    ...: df = pd.DataFrame({'a': pa.scalar(7)}, index=['a'])
    ...: print(type(df.to_dict(orient="records")[0]['a']))
    ...: 
<class 'pyarrow.lib.Int64Scalar'>

This is inconsistent with the corresponding op for NumPy backed types (xref #37571)

In [13]: import pandas as pd
    ...: import numpy as np
    ...: 
    ...: df = pd.DataFrame({'a': np.int(7)}, index=['a'])
    ...: print(type(df.to_dict(orient="records")[0]['a']))
    ...: 
<class 'int'>

In general we'd like to_dict to return Python native types if possible.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Arrowpyarrow functionalityBugDtype ConversionsUnexpected or buggy dtype conversionsExtensionArrayExtending pandas with custom dtypes or arrays.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions