Skip to content

Commit

Permalink
ARROW-7872: [C++/Python] Support conversion of list of structs to pandas
Browse files Browse the repository at this point in the history
It appears that all the code exists to to the conversion but struct wasn't included in the list.  Is there a way to ensure, this doesn't cause a python memory leak or some other weird gotcha?

Closes #6532 from emkornfield/ARROW-7872 and squashes the following commits:

b64ab68 <Micah Kornfield> ARROW-7872:  Support conversion of list of structs to pandas

Authored-by: Micah Kornfield <emkornfield@gmail.com>
Signed-off-by: Wes McKinney <wesm+git@apache.org>
  • Loading branch information
emkornfield authored and wesm committed Mar 6, 2020
1 parent 81176c2 commit 3afdc87
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions cpp/src/arrow/python/arrow_to_pandas.cc
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ static inline bool ListTypeSupported(const DataType& type) {
case Type::STRING:
case Type::DATE32:
case Type::DATE64:
case Type::STRUCT:
case Type::TIME32:
case Type::TIME64:
case Type::TIMESTAMP:
Expand Down
16 changes: 16 additions & 0 deletions python/pyarrow/tests/test_pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -1953,6 +1953,22 @@ def test_infer_numpy_array(self):

_check_pandas_roundtrip(df, expected_schema=expected_schema)

def test_to_list_of_structs_pandas(self):
ints = pa.array([1, 2, 3], pa.int32())
strings = pa.array([['a', 'b'], ['c', 'd'], ['e', 'f']],
pa.list_(pa.string()))
structs = pa.StructArray.from_arrays([ints, strings], ['f1', 'f2'])
data = pa.ListArray.from_arrays([0, 1, 3], structs)

expected = pd.Series([
[{'f1': 1, 'f2': ['a', 'b']}],
[{'f1': 2, 'f2': ['c', 'd']},
{'f1': 3, 'f2': ['e', 'f']}]
])

series = pd.Series(data.to_pandas())
tm.assert_series_equal(series, expected)

@pytest.mark.parametrize('t,data,expected', [
(
pa.int64,
Expand Down

0 comments on commit 3afdc87

Please sign in to comment.