# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.

import numpy as np
import pytest

import pyarrow as pa
import pyarrow.compute


all_array_types = [
    ('bool', [True, False, False, True, True]),
    ('uint8', np.arange(5)),
    ('int8', np.arange(5)),
    ('uint16', np.arange(5)),
    ('int16', np.arange(5)),
    ('uint32', np.arange(5)),
    ('int32', np.arange(5)),
    ('uint64', np.arange(5, 10)),
    ('int64', np.arange(5, 10)),
    ('float', np.arange(0, 0.5, 0.1)),
    ('double', np.arange(0, 0.5, 0.1)),
    ('string', ['a', 'b', None, 'ddd', 'ee']),
    ('binary', [b'a', b'b', b'c', b'ddd', b'ee']),
    (pa.binary(3), [b'abc', b'bcd', b'cde', b'def', b'efg']),
    (pa.list_(pa.int8()), [[1, 2], [3, 4], [5, 6], None, [9, 16]]),
    (pa.large_list(pa.int16()), [[1], [2, 3, 4], [5, 6], None, [9, 16]]),
    (pa.struct([('a', pa.int8()), ('b', pa.int8())]), [
     {'a': 1, 'b': 2}, None, {'a': 3, 'b': 4}, None, {'a': 5, 'b': 6}]),
]


numerical_arrow_types = [
    pa.int8(),
    pa.int16(),
    pa.int64(),
    pa.uint8(),
    pa.uint16(),
    pa.uint64(),
    pa.float32(),
    pa.float64()
]


@pytest.mark.parametrize('arrow_type', numerical_arrow_types)
def test_sum_array(arrow_type):
    arr = pa.array([1, 2, 3, 4], type=arrow_type)
    assert arr.sum() == 10
    assert pa.compute.sum(arr) == 10

    arr = pa.array([], type=arrow_type)
    assert arr.sum() == None  # noqa: E711
    assert pa.compute.sum(arr) == None  # noqa: E711


@pytest.mark.parametrize('arrow_type', numerical_arrow_types)
def test_sum_chunked_array(arrow_type):
    arr = pa.chunked_array([pa.array([1, 2, 3, 4], type=arrow_type)])
    assert pa.compute.sum(arr) == 10

    arr = pa.chunked_array([
        pa.array([1, 2], type=arrow_type), pa.array([3, 4], type=arrow_type)
    ])
    assert pa.compute.sum(arr) == 10

    arr = pa.chunked_array([
        pa.array([1, 2], type=arrow_type),
        pa.array([], type=arrow_type),
        pa.array([3, 4], type=arrow_type)
    ])
    assert pa.compute.sum(arr) == 10

    arr = pa.chunked_array((), type=arrow_type)
    print(arr, type(arr))
    assert arr.num_chunks == 0
    assert pa.compute.sum(arr) == None  # noqa: E711


@pytest.mark.parametrize(('ty', 'values'), all_array_types)
def test_take(ty, values):
    arr = pa.array(values, type=ty)
    for indices_type in [pa.int8(), pa.int64()]:
        indices = pa.array([0, 4, 2, None], type=indices_type)
        result = arr.take(indices)
        result.validate()
        expected = pa.array([values[0], values[4], values[2], None], type=ty)
        assert result.equals(expected)

        # empty indices
        indices = pa.array([], type=indices_type)
        result = arr.take(indices)
        result.validate()
        expected = pa.array([], type=ty)
        assert result.equals(expected)

    indices = pa.array([2, 5])
    with pytest.raises(IndexError):
        arr.take(indices)

    indices = pa.array([2, -1])
    with pytest.raises(IndexError):
        arr.take(indices)


def test_take_indices_types():
    arr = pa.array(range(5))

    for indices_type in ['uint8', 'int8', 'uint16', 'int16',
                         'uint32', 'int32', 'uint64', 'int64']:
        indices = pa.array([0, 4, 2, None], type=indices_type)
        result = arr.take(indices)
        result.validate()
        expected = pa.array([0, 4, 2, None])
        assert result.equals(expected)

    for indices_type in [pa.float32(), pa.float64()]:
        indices = pa.array([0, 4, 2], type=indices_type)
        with pytest.raises(NotImplementedError):
            arr.take(indices)


@pytest.mark.parametrize('ordered', [False, True])
def test_take_dictionary(ordered):
    arr = pa.DictionaryArray.from_arrays([0, 1, 2, 0, 1, 2], ['a', 'b', 'c'],
                                         ordered=ordered)
    result = arr.take(pa.array([0, 1, 3]))
    result.validate()
    assert result.to_pylist() == ['a', 'b', 'a']
    assert result.dictionary.to_pylist() == ['a', 'b', 'c']
    assert result.type.ordered is ordered


@pytest.mark.parametrize(('ty', 'values'), all_array_types)
def test_filter(ty, values):
    arr = pa.array(values, type=ty)

    mask = pa.array([True, False, False, True, None])
    result = arr.filter(mask, null_selection_behavior='drop')
    result.validate()
    assert result.equals(pa.array([values[0], values[3]], type=ty))
    result = arr.filter(mask, null_selection_behavior='emit_null')
    result.validate()
    assert result.equals(pa.array([values[0], values[3], None], type=ty))

    # non-boolean dtype
    mask = pa.array([0, 1, 0, 1, 0])
    with pytest.raises(NotImplementedError):
        arr.filter(mask)

    # wrong length
    mask = pa.array([True, False, True])
    with pytest.raises(ValueError, match="must all be the same length"):
        arr.filter(mask)


def test_filter_chunked_array():
    arr = pa.chunked_array([["a", None], ["c", "d", "e"]])
    expected_drop = pa.chunked_array([["a"], ["e"]])
    expected_null = pa.chunked_array([["a"], [None, "e"]])

    for mask in [
        # mask is array
        pa.array([True, False, None, False, True]),
        # mask is chunked array
        pa.chunked_array([[True, False, None], [False, True]]),
        # mask is python object
        [True, False, None, False, True]
    ]:
        result = arr.filter(mask)
        assert result.equals(expected_drop)
        result = arr.filter(mask, null_selection_behavior="emit_null")
        assert result.equals(expected_null)


def test_filter_record_batch():
    batch = pa.record_batch(
        [pa.array(["a", None, "c", "d", "e"])], names=["a'"])

    # mask is array
    mask = pa.array([True, False, None, False, True])
    result = batch.filter(mask)
    expected = pa.record_batch([pa.array(["a", "e"])], names=["a'"])
    assert result.equals(expected)

    result = batch.filter(mask, null_selection_behavior="emit_null")
    expected = pa.record_batch([pa.array(["a", None, "e"])], names=["a'"])
    assert result.equals(expected)


def test_filter_table():
    table = pa.table([pa.array(["a", None, "c", "d", "e"])], names=["a"])
    expected_drop = pa.table([pa.array(["a", "e"])], names=["a"])
    expected_null = pa.table([pa.array(["a", None, "e"])], names=["a"])

    for mask in [
        # mask is array
        pa.array([True, False, None, False, True]),
        # mask is chunked array
        pa.chunked_array([[True, False], [None, False, True]]),
        # mask is python object
        [True, False, None, False, True]
    ]:
        result = table.filter(mask)
        assert result.equals(expected_drop)
        result = table.filter(mask, null_selection_behavior="emit_null")
        assert result.equals(expected_null)


def test_filter_errors():
    arr = pa.chunked_array([["a", None], ["c", "d", "e"]])
    batch = pa.record_batch(
        [pa.array(["a", None, "c", "d", "e"])], names=["a'"])
    table = pa.table([pa.array(["a", None, "c", "d", "e"])], names=["a"])

    for obj in [arr, batch, table]:
        # non-boolean dtype
        mask = pa.array([0, 1, 0, 1, 0])
        with pytest.raises(NotImplementedError):
            obj.filter(mask)

        # wrong length
        mask = pa.array([True, False, True])
        with pytest.raises(pa.ArrowInvalid,
                           match="must all be the same length"):
            obj.filter(mask)


@pytest.mark.parametrize("typ", ["array", "chunked_array"])
def test_compare_array(typ):
    if typ == "array":
        def con(values): return pa.array(values)
    else:
        def con(values): return pa.chunked_array([values])

    arr1 = con([1, 2, 3, 4, None])
    arr2 = con([1, 1, 4, None, 4])

    result = arr1 == arr2
    assert result.equals(con([True, False, False, None, None]))

    result = arr1 != arr2
    assert result.equals(con([False, True, True, None, None]))

    result = arr1 < arr2
    assert result.equals(con([False, False, True, None, None]))

    result = arr1 <= arr2
    assert result.equals(con([True, False, True, None, None]))

    result = arr1 > arr2
    assert result.equals(con([False, True, False, None, None]))

    result = arr1 >= arr2
    assert result.equals(con([True, True, False, None, None]))


@pytest.mark.parametrize("typ", ["array", "chunked_array"])
def test_compare_scalar(typ):
    if typ == "array":
        def con(values): return pa.array(values)
    else:
        def con(values): return pa.chunked_array([values])

    arr = con([1, 2, 3, None])
    # TODO this is a hacky way to construct a scalar ..
    scalar = pa.array([2]).sum()

    result = arr == scalar
    assert result.equals(con([False, True, False, None]))

    result = arr != scalar
    assert result.equals(con([True, False, True, None]))

    result = arr < scalar
    assert result.equals(con([True, False, False, None]))

    result = arr <= scalar
    assert result.equals(con([True, True, False, None]))

    result = arr > scalar
    assert result.equals(con([False, False, True, None]))

    result = arr >= scalar
    assert result.equals(con([False, True, True, None]))


def test_compare_chunked_array_mixed():
    arr = pa.array([1, 2, 3, 4, None])
    arr_chunked = pa.chunked_array([[1, 2, 3], [4, None]])
    arr_chunked2 = pa.chunked_array([[1, 2], [3, 4, None]])

    expected = pa.chunked_array([[True, True, True, True, None]])

    for result in [
        arr == arr_chunked,
        arr_chunked == arr,
        arr_chunked == arr_chunked2,
    ]:
        assert result.equals(expected)


def test_arithmetic_add():
    left = pa.array([1, 2, 3, 4, 5])
    right = pa.array([0, -1, 1, 2, 3])
    result = pa.compute.add(left, right)
    expected = pa.array([1, 1, 4, 6, 8])
    assert result.equals(expected)


def test_arithmetic_subtract():
    left = pa.array([1, 2, 3, 4, 5])
    right = pa.array([0, -1, 1, 2, 3])
    result = pa.compute.subtract(left, right)
    expected = pa.array([1, 3, 2, 2, 2])
    assert result.equals(expected)


def test_arithmetic_multiply():
    left = pa.array([1, 2, 3, 4, 5])
    right = pa.array([0, -1, 1, 2, 3])
    result = pa.compute.multiply(left, right)
    expected = pa.array([0, -2, 3, 8, 15])
    assert result.equals(expected)

[((1853, 1913), 'pytest.mark.parametrize', 'pytest.mark.parametrize', (['"""arrow_type"""', 'numerical_arrow_types'], {}), "('arrow_type', numerical_arrow_types)\n", (1876, 1913), False, 'import pytest\n'), ((2200, 2260), 'pytest.mark.parametrize', 'pytest.mark.parametrize', (['"""arrow_type"""', 'numerical_arrow_types'], {}), "('arrow_type', numerical_arrow_types)\n", (2223, 2260), False, 'import pytest\n'), ((2919, 2977), 'pytest.mark.parametrize', 'pytest.mark.parametrize', (["('ty', 'values')", 'all_array_types'], {}), "(('ty', 'values'), all_array_types)\n", (2942, 2977), False, 'import pytest\n'), ((4326, 4375), 'pytest.mark.parametrize', 'pytest.mark.parametrize', (['"""ordered"""', '[False, True]'], {}), "('ordered', [False, True])\n", (4349, 4375), False, 'import pytest\n'), ((4766, 4824), 'pytest.mark.parametrize', 'pytest.mark.parametrize', (["('ty', 'values')", 'all_array_types'], {}), "(('ty', 'values'), all_array_types)\n", (4789, 4824), False, 'import pytest\n'), ((8090, 8148), 'pytest.mark.parametrize', 'pytest.mark.parametrize', (['"""typ"""', "['array', 'chunked_array']"], {}), "('typ', ['array', 'chunked_array'])\n", (8113, 8148), False, 'import pytest\n'), ((8934, 8992), 'pytest.mark.parametrize', 'pytest.mark.parametrize', (['"""typ"""', "['array', 'chunked_array']"], {}), "('typ', ['array', 'chunked_array'])\n", (8957, 8992), False, 'import pytest\n'), ((1720, 1729), 'pyarrow.int8', 'pa.int8', ([], {}), '()\n', (1727, 1729), True, 'import pyarrow as pa\n'), ((1735, 1745), 'pyarrow.int16', 'pa.int16', ([], {}), '()\n', (1743, 1745), True, 'import pyarrow as pa\n'), ((1751, 1761), 'pyarrow.int64', 'pa.int64', ([], {}), '()\n', (1759, 1761), True, 'import pyarrow as pa\n'), ((1767, 1777), 'pyarrow.uint8', 'pa.uint8', ([], {}), '()\n', (1775, 1777), True, 'import pyarrow as pa\n'), ((1783, 1794), 'pyarrow.uint16', 'pa.uint16', ([], {}), '()\n', (1792, 1794), True, 'import pyarrow as pa\n'), ((1800, 1811), 'pyarrow.uint64', 'pa.uint64', ([], {}), '()\n', (1809, 1811), True, 'import pyarrow as pa\n'), ((1817, 1829), 'pyarrow.float32', 'pa.float32', ([], {}), '()\n', (1827, 1829), True, 'import pyarrow as pa\n'), ((1835, 1847), 'pyarrow.float64', 'pa.float64', ([], {}), '()\n', (1845, 1847), True, 'import pyarrow as pa\n'), ((1956, 1995), 'pyarrow.array', 'pa.array', (['[1, 2, 3, 4]'], {'type': 'arrow_type'}), '([1, 2, 3, 4], type=arrow_type)\n', (1964, 1995), True, 'import pyarrow as pa\n'), ((2071, 2100), 'pyarrow.array', 'pa.array', (['[]'], {'type': 'arrow_type'}), '([], type=arrow_type)\n', (2079, 2100), True, 'import pyarrow as pa\n'), ((2768, 2805), 'pyarrow.chunked_array', 'pa.chunked_array', (['()'], {'type': 'arrow_type'}), '((), type=arrow_type)\n', (2784, 2805), True, 'import pyarrow as pa\n'), ((3015, 3040), 'pyarrow.array', 'pa.array', (['values'], {'type': 'ty'}), '(values, type=ty)\n', (3023, 3040), True, 'import pyarrow as pa\n'), ((3562, 3578), 'pyarrow.array', 'pa.array', (['[2, 5]'], {}), '([2, 5])\n', (3570, 3578), True, 'import pyarrow as pa\n'), ((3656, 3673), 'pyarrow.array', 'pa.array', (['[2, -1]'], {}), '([2, -1])\n', (3664, 3673), True, 'import pyarrow as pa\n'), ((4421, 4510), 'pyarrow.DictionaryArray.from_arrays', 'pa.DictionaryArray.from_arrays', (['[0, 1, 2, 0, 1, 2]', "['a', 'b', 'c']"], {'ordered': 'ordered'}), "([0, 1, 2, 0, 1, 2], ['a', 'b', 'c'], ordered\n    =ordered)\n", (4451, 4510), True, 'import pyarrow as pa\n'), ((4864, 4889), 'pyarrow.array', 'pa.array', (['values'], {'type': 'ty'}), '(values, type=ty)\n', (4872, 4889), True, 'import pyarrow as pa\n'), ((4902, 4944), 'pyarrow.array', 'pa.array', (['[True, False, False, True, None]'], {}), '([True, False, False, True, None])\n', (4910, 4944), True, 'import pyarrow as pa\n'), ((5296, 5321), 'pyarrow.array', 'pa.array', (['[0, 1, 0, 1, 0]'], {}), '([0, 1, 0, 1, 0])\n', (5304, 5321), True, 'import pyarrow as pa\n'), ((5423, 5452), 'pyarrow.array', 'pa.array', (['[True, False, True]'], {}), '([True, False, True])\n', (5431, 5452), True, 'import pyarrow as pa\n'), ((5596, 5644), 'pyarrow.chunked_array', 'pa.chunked_array', (["[['a', None], ['c', 'd', 'e']]"], {}), "([['a', None], ['c', 'd', 'e']])\n", (5612, 5644), True, 'import pyarrow as pa\n'), ((5665, 5697), 'pyarrow.chunked_array', 'pa.chunked_array', (["[['a'], ['e']]"], {}), "([['a'], ['e']])\n", (5681, 5697), True, 'import pyarrow as pa\n'), ((5718, 5756), 'pyarrow.chunked_array', 'pa.chunked_array', (["[['a'], [None, 'e']]"], {}), "([['a'], [None, 'e']])\n", (5734, 5756), True, 'import pyarrow as pa\n'), ((6378, 6420), 'pyarrow.array', 'pa.array', (['[True, False, None, False, True]'], {}), '([True, False, None, False, True])\n', (6386, 6420), True, 'import pyarrow as pa\n'), ((7482, 7530), 'pyarrow.chunked_array', 'pa.chunked_array', (["[['a', None], ['c', 'd', 'e']]"], {}), "([['a', None], ['c', 'd', 'e']])\n", (7498, 7530), True, 'import pyarrow as pa\n'), ((9848, 9876), 'pyarrow.array', 'pa.array', (['[1, 2, 3, 4, None]'], {}), '([1, 2, 3, 4, None])\n', (9856, 9876), True, 'import pyarrow as pa\n'), ((9895, 9935), 'pyarrow.chunked_array', 'pa.chunked_array', (['[[1, 2, 3], [4, None]]'], {}), '([[1, 2, 3], [4, None]])\n', (9911, 9935), True, 'import pyarrow as pa\n'), ((9955, 9995), 'pyarrow.chunked_array', 'pa.chunked_array', (['[[1, 2], [3, 4, None]]'], {}), '([[1, 2], [3, 4, None]])\n', (9971, 9995), True, 'import pyarrow as pa\n'), ((10012, 10062), 'pyarrow.chunked_array', 'pa.chunked_array', (['[[True, True, True, True, None]]'], {}), '([[True, True, True, True, None]])\n', (10028, 10062), True, 'import pyarrow as pa\n'), ((10263, 10288), 'pyarrow.array', 'pa.array', (['[1, 2, 3, 4, 5]'], {}), '([1, 2, 3, 4, 5])\n', (10271, 10288), True, 'import pyarrow as pa\n'), ((10301, 10327), 'pyarrow.array', 'pa.array', (['[0, -1, 1, 2, 3]'], {}), '([0, -1, 1, 2, 3])\n', (10309, 10327), True, 'import pyarrow as pa\n'), ((10341, 10368), 'pyarrow.compute.add', 'pa.compute.add', (['left', 'right'], {}), '(left, right)\n', (10355, 10368), True, 'import pyarrow as pa\n'), ((10384, 10409), 'pyarrow.array', 'pa.array', (['[1, 1, 4, 6, 8]'], {}), '([1, 1, 4, 6, 8])\n', (10392, 10409), True, 'import pyarrow as pa\n'), ((10490, 10515), 'pyarrow.array', 'pa.array', (['[1, 2, 3, 4, 5]'], {}), '([1, 2, 3, 4, 5])\n', (10498, 10515), True, 'import pyarrow as pa\n'), ((10528, 10554), 'pyarrow.array', 'pa.array', (['[0, -1, 1, 2, 3]'], {}), '([0, -1, 1, 2, 3])\n', (10536, 10554), True, 'import pyarrow as pa\n'), ((10568, 10600), 'pyarrow.compute.subtract', 'pa.compute.subtract', (['left', 'right'], {}), '(left, right)\n', (10587, 10600), True, 'import pyarrow as pa\n'), ((10616, 10641), 'pyarrow.array', 'pa.array', (['[1, 3, 2, 2, 2]'], {}), '([1, 3, 2, 2, 2])\n', (10624, 10641), True, 'import pyarrow as pa\n'), ((10722, 10747), 'pyarrow.array', 'pa.array', (['[1, 2, 3, 4, 5]'], {}), '([1, 2, 3, 4, 5])\n', (10730, 10747), True, 'import pyarrow as pa\n'), ((10760, 10786), 'pyarrow.array', 'pa.array', (['[0, -1, 1, 2, 3]'], {}), '([0, -1, 1, 2, 3])\n', (10768, 10786), True, 'import pyarrow as pa\n'), ((10800, 10832), 'pyarrow.compute.multiply', 'pa.compute.multiply', (['left', 'right'], {}), '(left, right)\n', (10819, 10832), True, 'import pyarrow as pa\n'), ((10848, 10875), 'pyarrow.array', 'pa.array', (['[0, -2, 3, 8, 15]'], {}), '([0, -2, 3, 8, 15])\n', (10856, 10875), True, 'import pyarrow as pa\n'), ((948, 960), 'numpy.arange', 'np.arange', (['(5)'], {}), '(5)\n', (957, 960), True, 'import numpy as np\n'), ((976, 988), 'numpy.arange', 'np.arange', (['(5)'], {}), '(5)\n', (985, 988), True, 'import numpy as np\n'), ((1006, 1018), 'numpy.arange', 'np.arange', (['(5)'], {}), '(5)\n', (1015, 1018), True, 'import numpy as np\n'), ((1035, 1047), 'numpy.arange', 'np.arange', (['(5)'], {}), '(5)\n', (1044, 1047), True, 'import numpy as np\n'), ((1065, 1077), 'numpy.arange', 'np.arange', (['(5)'], {}), '(5)\n', (1074, 1077), True, 'import numpy as np\n'), ((1094, 1106), 'numpy.arange', 'np.arange', (['(5)'], {}), '(5)\n', (1103, 1106), True, 'import numpy as np\n'), ((1124, 1140), 'numpy.arange', 'np.arange', (['(5)', '(10)'], {}), '(5, 10)\n', (1133, 1140), True, 'import numpy as np\n'), ((1157, 1173), 'numpy.arange', 'np.arange', (['(5)', '(10)'], {}), '(5, 10)\n', (1166, 1173), True, 'import numpy as np\n'), ((1190, 1212), 'numpy.arange', 'np.arange', (['(0)', '(0.5)', '(0.1)'], {}), '(0, 0.5, 0.1)\n', (1199, 1212), True, 'import numpy as np\n'), ((1230, 1252), 'numpy.arange', 'np.arange', (['(0)', '(0.5)', '(0.1)'], {}), '(0, 0.5, 0.1)\n', (1239, 1252), True, 'import numpy as np\n'), ((1358, 1370), 'pyarrow.binary', 'pa.binary', (['(3)'], {}), '(3)\n', (1367, 1370), True, 'import pyarrow as pa\n'), ((2034, 2053), 'pyarrow.compute.sum', 'pa.compute.sum', (['arr'], {}), '(arr)\n', (2048, 2053), True, 'import pyarrow as pa\n'), ((2155, 2174), 'pyarrow.compute.sum', 'pa.compute.sum', (['arr'], {}), '(arr)\n', (2169, 2174), True, 'import pyarrow as pa\n'), ((2382, 2401), 'pyarrow.compute.sum', 'pa.compute.sum', (['arr'], {}), '(arr)\n', (2396, 2401), True, 'import pyarrow as pa\n'), ((2533, 2552), 'pyarrow.compute.sum', 'pa.compute.sum', (['arr'], {}), '(arr)\n', (2547, 2552), True, 'import pyarrow as pa\n'), ((2731, 2750), 'pyarrow.compute.sum', 'pa.compute.sum', (['arr'], {}), '(arr)\n', (2745, 2750), True, 'import pyarrow as pa\n'), ((2874, 2893), 'pyarrow.compute.sum', 'pa.compute.sum', (['arr'], {}), '(arr)\n', (2888, 2893), True, 'import pyarrow as pa\n'), ((3066, 3075), 'pyarrow.int8', 'pa.int8', ([], {}), '()\n', (3073, 3075), True, 'import pyarrow as pa\n'), ((3077, 3087), 'pyarrow.int64', 'pa.int64', ([], {}), '()\n', (3085, 3087), True, 'import pyarrow as pa\n'), ((3108, 3152), 'pyarrow.array', 'pa.array', (['[0, 4, 2, None]'], {'type': 'indices_type'}), '([0, 4, 2, None], type=indices_type)\n', (3116, 3152), True, 'import pyarrow as pa\n'), ((3233, 3291), 'pyarrow.array', 'pa.array', (['[values[0], values[4], values[2], None]'], {'type': 'ty'}), '([values[0], values[4], values[2], None], type=ty)\n', (3241, 3291), True, 'import pyarrow as pa\n'), ((3374, 3405), 'pyarrow.array', 'pa.array', (['[]'], {'type': 'indices_type'}), '([], type=indices_type)\n', (3382, 3405), True, 'import pyarrow as pa\n'), ((3486, 3507), 'pyarrow.array', 'pa.array', (['[]'], {'type': 'ty'}), '([], type=ty)\n', (3494, 3507), True, 'import pyarrow as pa\n'), ((3588, 3613), 'pytest.raises', 'pytest.raises', (['IndexError'], {}), '(IndexError)\n', (3601, 3613), False, 'import pytest\n'), ((3683, 3708), 'pytest.raises', 'pytest.raises', (['IndexError'], {}), '(IndexError)\n', (3696, 3708), False, 'import pytest\n'), ((3942, 3986), 'pyarrow.array', 'pa.array', (['[0, 4, 2, None]'], {'type': 'indices_type'}), '([0, 4, 2, None], type=indices_type)\n', (3950, 3986), True, 'import pyarrow as pa\n'), ((4067, 4092), 'pyarrow.array', 'pa.array', (['[0, 4, 2, None]'], {}), '([0, 4, 2, None])\n', (4075, 4092), True, 'import pyarrow as pa\n'), ((4158, 4170), 'pyarrow.float32', 'pa.float32', ([], {}), '()\n', (4168, 4170), True, 'import pyarrow as pa\n'), ((4172, 4184), 'pyarrow.float64', 'pa.float64', ([], {}), '()\n', (4182, 4184), True, 'import pyarrow as pa\n'), ((4205, 4243), 'pyarrow.array', 'pa.array', (['[0, 4, 2]'], {'type': 'indices_type'}), '([0, 4, 2], type=indices_type)\n', (4213, 4243), True, 'import pyarrow as pa\n'), ((4569, 4588), 'pyarrow.array', 'pa.array', (['[0, 1, 3]'], {}), '([0, 1, 3])\n', (4577, 4588), True, 'import pyarrow as pa\n'), ((5054, 5095), 'pyarrow.array', 'pa.array', (['[values[0], values[3]]'], {'type': 'ty'}), '([values[0], values[3]], type=ty)\n', (5062, 5095), True, 'import pyarrow as pa\n'), ((5211, 5258), 'pyarrow.array', 'pa.array', (['[values[0], values[3], None]'], {'type': 'ty'}), '([values[0], values[3], None], type=ty)\n', (5219, 5258), True, 'import pyarrow as pa\n'), ((5331, 5365), 'pytest.raises', 'pytest.raises', (['NotImplementedError'], {}), '(NotImplementedError)\n', (5344, 5365), False, 'import pytest\n'), ((5462, 5524), 'pytest.raises', 'pytest.raises', (['ValueError'], {'match': '"""must all be the same length"""'}), "(ValueError, match='must all be the same length')\n", (5475, 5524), False, 'import pytest\n'), ((5808, 5850), 'pyarrow.array', 'pa.array', (['[True, False, None, False, True]'], {}), '([True, False, None, False, True])\n', (5816, 5850), True, 'import pyarrow as pa\n'), ((5892, 5946), 'pyarrow.chunked_array', 'pa.chunked_array', (['[[True, False, None], [False, True]]'], {}), '([[True, False, None], [False, True]])\n', (5908, 5946), True, 'import pyarrow as pa\n'), ((7027, 7069), 'pyarrow.array', 'pa.array', (['[True, False, None, False, True]'], {}), '([True, False, None, False, True])\n', (7035, 7069), True, 'import pyarrow as pa\n'), ((7111, 7165), 'pyarrow.chunked_array', 'pa.chunked_array', (['[[True, False], [None, False, True]]'], {}), '([[True, False], [None, False, True]])\n', (7127, 7165), True, 'import pyarrow as pa\n'), ((7776, 7801), 'pyarrow.array', 'pa.array', (['[0, 1, 0, 1, 0]'], {}), '([0, 1, 0, 1, 0])\n', (7784, 7801), True, 'import pyarrow as pa\n'), ((7919, 7948), 'pyarrow.array', 'pa.array', (['[True, False, True]'], {}), '([True, False, True])\n', (7927, 7948), True, 'import pyarrow as pa\n'), ((1429, 1438), 'pyarrow.int8', 'pa.int8', ([], {}), '()\n', (1436, 1438), True, 'import pyarrow as pa\n'), ((1502, 1512), 'pyarrow.int16', 'pa.int16', ([], {}), '()\n', (1510, 1512), True, 'import pyarrow as pa\n'), ((2329, 2368), 'pyarrow.array', 'pa.array', (['[1, 2, 3, 4]'], {'type': 'arrow_type'}), '([1, 2, 3, 4], type=arrow_type)\n', (2337, 2368), True, 'import pyarrow as pa\n'), ((2446, 2479), 'pyarrow.array', 'pa.array', (['[1, 2]'], {'type': 'arrow_type'}), '([1, 2], type=arrow_type)\n', (2454, 2479), True, 'import pyarrow as pa\n'), ((2481, 2514), 'pyarrow.array', 'pa.array', (['[3, 4]'], {'type': 'arrow_type'}), '([3, 4], type=arrow_type)\n', (2489, 2514), True, 'import pyarrow as pa\n'), ((2597, 2630), 'pyarrow.array', 'pa.array', (['[1, 2]'], {'type': 'arrow_type'}), '([1, 2], type=arrow_type)\n', (2605, 2630), True, 'import pyarrow as pa\n'), ((2640, 2669), 'pyarrow.array', 'pa.array', (['[]'], {'type': 'arrow_type'}), '([], type=arrow_type)\n', (2648, 2669), True, 'import pyarrow as pa\n'), ((2679, 2712), 'pyarrow.array', 'pa.array', (['[3, 4]'], {'type': 'arrow_type'}), '([3, 4], type=arrow_type)\n', (2687, 2712), True, 'import pyarrow as pa\n'), ((4257, 4291), 'pytest.raises', 'pytest.raises', (['NotImplementedError'], {}), '(NotImplementedError)\n', (4270, 4291), False, 'import pytest\n'), ((6293, 6329), 'pyarrow.array', 'pa.array', (["['a', None, 'c', 'd', 'e']"], {}), "(['a', None, 'c', 'd', 'e'])\n", (6301, 6329), True, 'import pyarrow as pa\n'), ((6485, 6505), 'pyarrow.array', 'pa.array', (["['a', 'e']"], {}), "(['a', 'e'])\n", (6493, 6505), True, 'import pyarrow as pa\n'), ((6659, 6685), 'pyarrow.array', 'pa.array', (["['a', None, 'e']"], {}), "(['a', None, 'e'])\n", (6667, 6685), True, 'import pyarrow as pa\n'), ((6786, 6822), 'pyarrow.array', 'pa.array', (["['a', None, 'c', 'd', 'e']"], {}), "(['a', None, 'c', 'd', 'e'])\n", (6794, 6822), True, 'import pyarrow as pa\n'), ((6868, 6888), 'pyarrow.array', 'pa.array', (["['a', 'e']"], {}), "(['a', 'e'])\n", (6876, 6888), True, 'import pyarrow as pa\n'), ((6934, 6960), 'pyarrow.array', 'pa.array', (["['a', None, 'e']"], {}), "(['a', None, 'e'])\n", (6942, 6960), True, 'import pyarrow as pa\n'), ((7569, 7605), 'pyarrow.array', 'pa.array', (["['a', None, 'c', 'd', 'e']"], {}), "(['a', None, 'c', 'd', 'e'])\n", (7577, 7605), True, 'import pyarrow as pa\n'), ((7644, 7680), 'pyarrow.array', 'pa.array', (["['a', None, 'c', 'd', 'e']"], {}), "(['a', None, 'c', 'd', 'e'])\n", (7652, 7680), True, 'import pyarrow as pa\n'), ((7815, 7849), 'pytest.raises', 'pytest.raises', (['NotImplementedError'], {}), '(NotImplementedError)\n', (7828, 7849), False, 'import pytest\n'), ((7962, 8029), 'pytest.raises', 'pytest.raises', (['pa.ArrowInvalid'], {'match': '"""must all be the same length"""'}), "(pa.ArrowInvalid, match='must all be the same length')\n", (7975, 8029), False, 'import pytest\n'), ((8233, 8249), 'pyarrow.array', 'pa.array', (['values'], {}), '(values)\n', (8241, 8249), True, 'import pyarrow as pa\n'), ((8292, 8318), 'pyarrow.chunked_array', 'pa.chunked_array', (['[values]'], {}), '([values])\n', (8308, 8318), True, 'import pyarrow as pa\n'), ((9078, 9094), 'pyarrow.array', 'pa.array', (['values'], {}), '(values)\n', (9086, 9094), True, 'import pyarrow as pa\n'), ((9137, 9163), 'pyarrow.chunked_array', 'pa.chunked_array', (['[values]'], {}), '([values])\n', (9153, 9163), True, 'import pyarrow as pa\n'), ((9265, 9278), 'pyarrow.array', 'pa.array', (['[2]'], {}), '([2])\n', (9273, 9278), True, 'import pyarrow as pa\n'), ((1579, 1588), 'pyarrow.int8', 'pa.int8', ([], {}), '()\n', (1586, 1588), True, 'import pyarrow as pa\n'), ((1597, 1606), 'pyarrow.int8', 'pa.int8', ([], {}), '()\n', (1604, 1606), True, 'import pyarrow as pa\n')]