[ https://issues.apache.org/jira/browse/ARROW-2073?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16355919#comment-16355919 ]
ASF GitHub Bot commented on ARROW-2073: --------------------------------------- xhochy commented on a change in pull request #1572: ARROW-2073: [Python] Create struct array from sequence of tuples URL: https://github.com/apache/arrow/pull/1572#discussion_r166726751 ########## File path: python/pyarrow/tests/test_convert_builtin.py ########## @@ -531,6 +531,45 @@ def test_struct_from_dicts(): assert arr.to_pylist() == expected +def test_struct_from_tuples(): + ty = pa.struct([pa.field('a', pa.int32()), + pa.field('b', pa.string()), + pa.field('c', pa.bool_())]) + + data = [(5, 'foo', True), + (6, 'bar', False)] + expected = [{'a': 5, 'b': 'foo', 'c': True}, + {'a': 6, 'b': 'bar', 'c': False}] + arr = pa.array(data, type=ty) + assert arr.to_pylist() == expected + + # With omitted values + data = [(5, 'foo', None), + None, + (6, None, False)] + expected = [{'a': 5, 'b': 'foo', 'c': None}, + None, + {'a': 6, 'b': None, 'c': False}] + arr = pa.array(data, type=ty) + assert arr.to_pylist() == expected + + # Invalid tuple size + for tup in [(5, 'foo'), (), ('5', 'foo', True, None)]: + with pytest.raises(ValueError, match="(?i)tuple size"): + pa.array([tup], type=ty) + + +def test_struct_from_mixed_sequence(): + # It is forgotten to mix dicts and tuples when initializing a struct array Review comment: Typo: s/forgotten/forbidden/ ---------------------------------------------------------------- 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] Create StructArray from sequence of tuples given a known data type > --------------------------------------------------------------------------- > > Key: ARROW-2073 > URL: https://issues.apache.org/jira/browse/ARROW-2073 > Project: Apache Arrow > Issue Type: Improvement > Components: Python > Reporter: Antoine Pitrou > Assignee: Antoine Pitrou > Priority: Major > Labels: pull-request-available > > Following ARROW-1705, we should support calling {{pa.array}} with a sequence > of tuples, presuming a struct type is passed for the {{type}} parameter. > We also probably want to disallow mixed inputs, e.g. a sequence of both dicts > and tuples. The user should use only one idiom at a time. -- This message was sent by Atlassian JIRA (v7.6.3#76005)