diff --git a/python/pyarrow/tests/test_convert_builtin.py b/python/pyarrow/tests/test_convert_builtin.py index e2670aaed6e58..315f2c6967415 100644 --- a/python/pyarrow/tests/test_convert_builtin.py +++ b/python/pyarrow/tests/test_convert_builtin.py @@ -2365,39 +2365,54 @@ def test_array_from_pylist_offset_overflow(): assert len(arr.chunks) > 1 -@parametrize_with_collections_types -@pytest.mark.parametrize(('data', 'scalar_data'), [ - ([True, False, None], [pa.scalar(True), pa.scalar(False), None]), - ([1, 2, None], [pa.scalar(1), pa.scalar(2), None]), - ([1, None, None], [pa.scalar(1), None, pa.scalar(None, type=pa.int64())]), - ([None, None], [pa.scalar(None), pa.scalar(None)]), - ([1., 2., None], [pa.scalar(1.), pa.scalar(2.), None]), - ([None, datetime.date.today()], [None, pa.scalar(datetime.date.today())]), - ([datetime.time(1, 1, 1), None], [pa.scalar(datetime.time(1, 1, 1)), None]), - ([datetime.timedelta(seconds=10)], [pa.scalar(datetime.timedelta(seconds=10))]), - ([None, datetime.datetime(2014, 1, 1)], [ - None, pa.scalar(datetime.datetime(2014, 1, 1))]), - ([pa.MonthDayNano([1, -1, -10100])], [pa.scalar(pa.MonthDayNano([1, -1, -10100]))]), - (["a", "b"], [pa.scalar("a"), pa.scalar("b")]), - ([b"a", b"b"], [pa.scalar(b"a"), pa.scalar(b"b")]), - ([[1, 2, 3]], [pa.scalar([1, 2, 3])]), - ([["a", "b"]], [pa.scalar(["a", "b"])]), -]) -def test_array_accepts_pyarrow_scalar(seq, data, scalar_data): - if type(seq(scalar_data)) == set: - pytest.skip("TODO: look at the reordering of the elements in the set") - expect = pa.array(data) - result = pa.array(seq(scalar_data)) - assert expect.equals(result) - - @parametrize_with_collections_types @pytest.mark.parametrize(('data', 'scalar_data', 'value_type'), [ - ([1, 2, None], [pa.scalar(1, type=pa.int8()), - pa.scalar(2, type=pa.int8()), None], pa.int8()), + ([True, False, None], [pa.scalar(True), pa.scalar(False), None], pa.bool_()), + ([1, 2, None], [pa.scalar(1), pa.scalar(2), None], pa.int64()), + ([1, None, None], [pa.scalar(1), None, pa.scalar(None, pa.int64())], pa.int64()), + ([None, None], [pa.scalar(None), pa.scalar(None)], pa.null()), + ([1., 2., None], [pa.scalar(1.), pa.scalar(2.), None], pa.float64()), + ( + [None, datetime.date.today()], + [None, pa.scalar(datetime.date.today())], + pa.date32()), + ( + [datetime.time(1, 1, 1), None], + [pa.scalar(datetime.time(1, 1, 1)), None], + pa.time64('us')), + ( + [datetime.timedelta(seconds=10)], + [pa.scalar(datetime.timedelta(seconds=10))], + pa.duration('us')), + ( + [None, datetime.datetime(2014, 1, 1)], + [None, pa.scalar(datetime.datetime(2014, 1, 1))], + pa.timestamp('us') + ), + ( + [pa.MonthDayNano([1, -1, -10100])], + [pa.scalar(pa.MonthDayNano([1, -1, -10100]))], + pa.month_day_nano_interval() + ), + (["a", "b"], [pa.scalar("a"), pa.scalar("b")], pa.string()), + ([b"a", b"b"], [pa.scalar(b"a"), pa.scalar(b"b")], pa.binary()), + ( + [b"a", b"b"], + [pa.scalar(b"a", pa.binary(1)), pa.scalar(b"b", pa.binary(1))], + pa.binary(1) + ), + ([[1, 2, 3]], [pa.scalar([1, 2, 3])], pa.list_(pa.int64())), + ([["a", "b"]], [pa.scalar(["a", "b"])], pa.list_(pa.string())), + ( + [1, 2, None], + [pa.scalar(1, type=pa.int8()), pa.scalar(2, type=pa.int8()), None], + pa.int8() + ), ([1, None], [pa.scalar(1.0, type=pa.int32()), None], pa.int32()), - (["aaa", "bbb"], [pa.scalar("aaa", type=pa.binary(3)), - pa.scalar("bbb", type=pa.binary(3))], pa.binary(3)), + ( + ["aaa", "bbb"], + [pa.scalar("aaa", type=pa.binary(3)), pa.scalar("bbb", type=pa.binary(3))], + pa.binary(3)), ([b"a"], [pa.scalar("a", type=pa.large_binary())], pa.large_binary()), (["a"], [pa.scalar("a", type=pa.large_string())], pa.large_string()), ( @@ -2429,10 +2444,13 @@ def test_array_accepts_pyarrow_scalar(seq, data, scalar_data): pa.struct([('a', pa.int8()), ('b', pa.string())]) ) ]) -def test_array_accepts_pyarrow_scalar_with_type(seq, data, scalar_data, value_type): +def test_array_accepts_pyarrow_scalar(seq, data, scalar_data, value_type): if type(seq(scalar_data)) == set: - pytest.skip("TODO: look at the reordering of the elements in the set") + pytest.skip("TODO: The elements in the set get reordered.") expect = pa.array(data, type=value_type) + result = pa.array(seq(scalar_data)) + assert expect.equals(result) + result = pa.array(seq(scalar_data), type=value_type) assert expect.equals(result)