Skip to content

[Python] How to convert list of dicts in Pandas to pyarrow Table? #3804

Closed

Description

@jezeniel

I have a pandas dataframe. One column has a list of python dictionaries.

[{"number": 1, "number_normalized": 1}, {"number": 2, "number_normalized" 2}]

I tried creating a schema for this a list of struct. But when I do this it is raising an error:

Traceback (most recent call last):
  File "test.py", line 47, in <module>
    table = pa.Table.from_pandas(df, schema=phone_contacts, preserve_index=False)
  File "pyarrow/table.pxi", line 1141, in pyarrow.lib.Table.from_pandas
  File "/home/jezeniel/.virtualenvs/data-archive/lib/python3.6/site-packages/pyarrow/pandas_compat.py", line 443, in dataframe_to_arrays
    types
  File "/home/jezeniel/.virtualenvs/data-archive/lib/python3.6/site-packages/pyarrow/pandas_compat.py", line 217, in construct_metadata
    df.columns, column_names, df_types
  File "/home/jezeniel/.virtualenvs/data-archive/lib/python3.6/site-packages/pyarrow/pandas_compat.py", line 216, in <listcomp>
    ) for col_name, sanitized_name, arrow_type in zip(
  File "/home/jezeniel/.virtualenvs/data-archive/lib/python3.6/site-packages/pyarrow/pandas_compat.py", line 160, in get_column_metadata
    logical_type = get_logical_type(arrow_type)
  File "/home/jezeniel/.virtualenvs/data-archive/lib/python3.6/site-packages/pyarrow/pandas_compat.py", line 87, in get_logical_type
    raise NotImplementedError(str(arrow_type))
NotImplementedError: struct<number: string, number_normalized: string>

Is there a way to convert this structure? or currently it is impossible?

Activity

  1. wesm commented on Mar 5, 2019

    @wesm
    Member

    Can you please open a JIRA issue? It would be great if you could include the phone_schema declaration also

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions