[ https://issues.apache.org/jira/browse/ARROW-1886?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16407666#comment-16407666 ]
ASF GitHub Bot commented on ARROW-1886: --------------------------------------- pitrou commented on a change in pull request #1768: ARROW-1886: [C++/Python] Flatten struct columns in table URL: https://github.com/apache/arrow/pull/1768#discussion_r176019996 ########## File path: python/pyarrow/tests/test_table.py ########## @@ -335,12 +348,34 @@ def test_table_remove_column_empty(): table = pa.Table.from_arrays(data, names=['a']) t2 = table.remove_column(0) + t2._validate() assert len(t2) == len(table) t3 = t2.add_column(0, table[0]) + t3._validate() assert t3.equals(table) +def test_table_flatten(): + ty1 = pa.struct([pa.field('x', pa.int16()), + pa.field('y', pa.float32())]) + ty2 = pa.struct([pa.field('nest', ty1)]) + a = pa.array([(1, 2.5), (3, 4.5)], type=ty1) + b = pa.array([((11, 12.5),), ((13, 14.5),)], type=ty2) + c = pa.array([False, True], type=pa.bool_()) + + table = pa.Table.from_arrays([a, b, c], names=['a', 'b', 'c']) + t2 = table.flatten() + t2._validate() + expected = pa.Table.from_arrays([ + pa.array([1, 3], type=pa.int16()), + pa.array([2.5, 4.5], type=pa.float32()), + pa.array([(11, 12.5), (13, 14.5)], type=ty1), + c], + names=['a.x', 'a.y', 'b.nest', 'c']) Review comment: I'm not sure we should deal with them ourselves? I *think* users can reimplement the table-flattening functionality themselves using `array.flatten` (if they want another naming scheme), though I'm not sure how easy that is with the currently exposed APIs. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org > [Python] Add function to "flatten" structs within tables > -------------------------------------------------------- > > Key: ARROW-1886 > URL: https://issues.apache.org/jira/browse/ARROW-1886 > Project: Apache Arrow > Issue Type: Improvement > Components: Python > Reporter: Wes McKinney > Assignee: Antoine Pitrou > Priority: Major > Labels: pull-request-available > Fix For: 0.10.0 > > > See discussion in https://issues.apache.org/jira/browse/ARROW-1873 > When a user has a struct column, it may be more efficient to flatten the > struct into multiple columns of the form {{struct_name.field_name}} for each > field in the struct. Then when you call {{to_pandas}}, Python dictionaries do > not have to be created, and the conversion will be much more efficient -- This message was sent by Atlassian JIRA (v7.6.3#76005)