# 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)

[((59, 1, 59, 61), 'pytest.mark.parametrize', 'pytest.mark.parametrize', ({(59, 25, 59, 37): '"""arrow_type"""', (59, 39, 59, 60): 'numerical_arrow_types'}, {}), "('arrow_type', numerical_arrow_types)", False, 'import pytest\n'), ((70, 1, 70, 61), 'pytest.mark.parametrize', 'pytest.mark.parametrize', ({(70, 25, 70, 37): '"""arrow_type"""', (70, 39, 70, 60): 'numerical_arrow_types'}, {}), "('arrow_type', numerical_arrow_types)", False, 'import pytest\n'), ((93, 1, 93, 59), 'pytest.mark.parametrize', 'pytest.mark.parametrize', ({(93, 25, 93, 41): "('ty', 'values')", (93, 43, 93, 58): 'all_array_types'}, {}), "(('ty', 'values'), all_array_types)", False, 'import pytest\n'), ((136, 1, 136, 50), 'pytest.mark.parametrize', 'pytest.mark.parametrize', ({(136, 25, 136, 34): '"""ordered"""', (136, 36, 136, 49): '[False, True]'}, {}), "('ordered', [False, True])", False, 'import pytest\n'), ((147, 1, 147, 59), 'pytest.mark.parametrize', 'pytest.mark.parametrize', ({(147, 25, 147, 41): "('ty', 'values')", (147, 43, 147, 58): 'all_array_types'}, {}), "(('ty', 'values'), all_array_types)", False, 'import pytest\n'), ((242, 1, 242, 59), 'pytest.mark.parametrize', 'pytest.mark.parametrize', ({(242, 25, 242, 30): '"""typ"""', (242, 32, 242, 58): "['array', 'chunked_array']"}, {}), "('typ', ['array', 'chunked_array'])", False, 'import pytest\n'), ((271, 1, 271, 59), 'pytest.mark.parametrize', 'pytest.mark.parametrize', ({(271, 25, 271, 30): '"""typ"""', (271, 32, 271, 58): "['array', 'chunked_array']"}, {}), "('typ', ['array', 'chunked_array'])", False, 'import pytest\n'), ((48, 4, 48, 13), 'pyarrow.int8', 'pa.int8', ({}, {}), '()', True, 'import pyarrow as pa\n'), ((49, 4, 49, 14), 'pyarrow.int16', 'pa.int16', ({}, {}), '()', True, 'import pyarrow as pa\n'), ((50, 4, 50, 14), 'pyarrow.int64', 'pa.int64', ({}, {}), '()', True, 'import pyarrow as pa\n'), ((51, 4, 51, 14), 'pyarrow.uint8', 'pa.uint8', ({}, {}), '()', True, 'import pyarrow as pa\n'), ((52, 4, 52, 15), 'pyarrow.uint16', 'pa.uint16', ({}, {}), '()', True, 'import pyarrow as pa\n'), ((53, 4, 53, 15), 'pyarrow.uint64', 'pa.uint64', ({}, {}), '()', True, 'import pyarrow as pa\n'), ((54, 4, 54, 16), 'pyarrow.float32', 'pa.float32', ({}, {}), '()', True, 'import pyarrow as pa\n'), ((55, 4, 55, 16), 'pyarrow.float64', 'pa.float64', ({}, {}), '()', True, 'import pyarrow as pa\n'), ((61, 10, 61, 49), 'pyarrow.array', 'pa.array', (), '', True, 'import pyarrow as pa\n'), ((65, 10, 65, 39), 'pyarrow.array', 'pa.array', (), '', True, 'import pyarrow as pa\n'), ((87, 10, 87, 47), 'pyarrow.chunked_array', 'pa.chunked_array', (), '', True, 'import pyarrow as pa\n'), ((95, 10, 95, 35), 'pyarrow.array', 'pa.array', (), '', True, 'import pyarrow as pa\n'), ((110, 14, 110, 30), 'pyarrow.array', 'pa.array', ({(110, 23, 110, 29): '[2, 5]'}, {}), '([2, 5])', True, 'import pyarrow as pa\n'), ((114, 14, 114, 31), 'pyarrow.array', 'pa.array', ({(114, 23, 114, 30): '[2, -1]'}, {}), '([2, -1])', True, 'import pyarrow as pa\n'), ((138, 10, 139, 57), 'pyarrow.DictionaryArray.from_arrays', 'pa.DictionaryArray.from_arrays', (), '', True, 'import pyarrow as pa\n'), ((149, 10, 149, 35), 'pyarrow.array', 'pa.array', (), '', True, 'import pyarrow as pa\n'), ((151, 11, 151, 53), 'pyarrow.array', 'pa.array', ({(151, 20, 151, 52): '[True, False, False, True, None]'}, {}), '([True, False, False, True, None])', True, 'import pyarrow as pa\n'), ((160, 11, 160, 36), 'pyarrow.array', 'pa.array', ({(160, 20, 160, 35): '[0, 1, 0, 1, 0]'}, {}), '([0, 1, 0, 1, 0])', True, 'import pyarrow as pa\n'), ((165, 11, 165, 40), 'pyarrow.array', 'pa.array', ({(165, 20, 165, 39): '[True, False, True]'}, {}), '([True, False, True])', True, 'import pyarrow as pa\n'), ((171, 10, 171, 58), 'pyarrow.chunked_array', 'pa.chunked_array', ({(171, 27, 171, 57): "[['a', None], ['c', 'd', 'e']]"}, {}), "([['a', None], ['c', 'd', 'e']])", True, 'import pyarrow as pa\n'), ((172, 20, 172, 52), 'pyarrow.chunked_array', 'pa.chunked_array', ({(172, 37, 172, 51): "[['a'], ['e']]"}, {}), "([['a'], ['e']])", True, 'import pyarrow as pa\n'), ((173, 20, 173, 58), 'pyarrow.chunked_array', 'pa.chunked_array', ({(173, 37, 173, 57): "[['a'], [None, 'e']]"}, {}), "([['a'], [None, 'e']])", True, 'import pyarrow as pa\n'), ((194, 11, 194, 53), 'pyarrow.array', 'pa.array', ({(194, 20, 194, 52): '[True, False, None, False, True]'}, {}), '([True, False, None, False, True])', True, 'import pyarrow as pa\n'), ((224, 10, 224, 58), 'pyarrow.chunked_array', 'pa.chunked_array', ({(224, 27, 224, 57): "[['a', None], ['c', 'd', 'e']]"}, {}), "([['a', None], ['c', 'd', 'e']])", True, 'import pyarrow as pa\n'), ((302, 10, 302, 38), 'pyarrow.array', 'pa.array', ({(302, 19, 302, 37): '[1, 2, 3, 4, None]'}, {}), '([1, 2, 3, 4, None])', True, 'import pyarrow as pa\n'), ((303, 18, 303, 58), 'pyarrow.chunked_array', 'pa.chunked_array', ({(303, 35, 303, 57): '[[1, 2, 3], [4, None]]'}, {}), '([[1, 2, 3], [4, None]])', True, 'import pyarrow as pa\n'), ((304, 19, 304, 59), 'pyarrow.chunked_array', 'pa.chunked_array', ({(304, 36, 304, 58): '[[1, 2], [3, 4, None]]'}, {}), '([[1, 2], [3, 4, None]])', True, 'import pyarrow as pa\n'), ((306, 15, 306, 65), 'pyarrow.chunked_array', 'pa.chunked_array', ({(306, 32, 306, 64): '[[True, True, True, True, None]]'}, {}), '([[True, True, True, True, None]])', True, 'import pyarrow as pa\n'), ((317, 11, 317, 36), 'pyarrow.array', 'pa.array', ({(317, 20, 317, 35): '[1, 2, 3, 4, 5]'}, {}), '([1, 2, 3, 4, 5])', True, 'import pyarrow as pa\n'), ((318, 12, 318, 38), 'pyarrow.array', 'pa.array', ({(318, 21, 318, 37): '[0, -1, 1, 2, 3]'}, {}), '([0, -1, 1, 2, 3])', True, 'import pyarrow as pa\n'), ((319, 13, 319, 40), 'pyarrow.compute.add', 'pa.compute.add', ({(319, 28, 319, 32): 'left', (319, 34, 319, 39): 'right'}, {}), '(left, right)', True, 'import pyarrow as pa\n'), ((320, 15, 320, 40), 'pyarrow.array', 'pa.array', ({(320, 24, 320, 39): '[1, 1, 4, 6, 8]'}, {}), '([1, 1, 4, 6, 8])', True, 'import pyarrow as pa\n'), ((325, 11, 325, 36), 'pyarrow.array', 'pa.array', ({(325, 20, 325, 35): '[1, 2, 3, 4, 5]'}, {}), '([1, 2, 3, 4, 5])', True, 'import pyarrow as pa\n'), ((326, 12, 326, 38), 'pyarrow.array', 'pa.array', ({(326, 21, 326, 37): '[0, -1, 1, 2, 3]'}, {}), '([0, -1, 1, 2, 3])', True, 'import pyarrow as pa\n'), ((327, 13, 327, 45), 'pyarrow.compute.subtract', 'pa.compute.subtract', ({(327, 33, 327, 37): 'left', (327, 39, 327, 44): 'right'}, {}), '(left, right)', True, 'import pyarrow as pa\n'), ((328, 15, 328, 40), 'pyarrow.array', 'pa.array', ({(328, 24, 328, 39): '[1, 3, 2, 2, 2]'}, {}), '([1, 3, 2, 2, 2])', True, 'import pyarrow as pa\n'), ((333, 11, 333, 36), 'pyarrow.array', 'pa.array', ({(333, 20, 333, 35): '[1, 2, 3, 4, 5]'}, {}), '([1, 2, 3, 4, 5])', True, 'import pyarrow as pa\n'), ((334, 12, 334, 38), 'pyarrow.array', 'pa.array', ({(334, 21, 334, 37): '[0, -1, 1, 2, 3]'}, {}), '([0, -1, 1, 2, 3])', True, 'import pyarrow as pa\n'), ((335, 13, 335, 45), 'pyarrow.compute.multiply', 'pa.compute.multiply', ({(335, 33, 335, 37): 'left', (335, 39, 335, 44): 'right'}, {}), '(left, right)', True, 'import pyarrow as pa\n'), ((336, 15, 336, 42), 'pyarrow.array', 'pa.array', ({(336, 24, 336, 41): '[0, -2, 3, 8, 15]'}, {}), '([0, -2, 3, 8, 15])', True, 'import pyarrow as pa\n'), ((27, 14, 27, 26), 'numpy.arange', 'np.arange', ({(27, 24, 27, 25): '(5)'}, {}), '(5)', True, 'import numpy as np\n'), ((28, 13, 28, 25), 'numpy.arange', 'np.arange', ({(28, 23, 28, 24): '(5)'}, {}), '(5)', True, 'import numpy as np\n'), ((29, 15, 29, 27), 'numpy.arange', 'np.arange', ({(29, 25, 29, 26): '(5)'}, {}), '(5)', True, 'import numpy as np\n'), ((30, 14, 30, 26), 'numpy.arange', 'np.arange', ({(30, 24, 30, 25): '(5)'}, {}), '(5)', True, 'import numpy as np\n'), ((31, 15, 31, 27), 'numpy.arange', 'np.arange', ({(31, 25, 31, 26): '(5)'}, {}), '(5)', True, 'import numpy as np\n'), ((32, 14, 32, 26), 'numpy.arange', 'np.arange', ({(32, 24, 32, 25): '(5)'}, {}), '(5)', True, 'import numpy as np\n'), ((33, 15, 33, 31), 'numpy.arange', 'np.arange', ({(33, 25, 33, 26): '(5)', (33, 28, 33, 30): '(10)'}, {}), '(5, 10)', True, 'import numpy as np\n'), ((34, 14, 34, 30), 'numpy.arange', 'np.arange', ({(34, 24, 34, 25): '(5)', (34, 27, 34, 29): '(10)'}, {}), '(5, 10)', True, 'import numpy as np\n'), ((35, 14, 35, 36), 'numpy.arange', 'np.arange', ({(35, 24, 35, 25): '(0)', (35, 27, 35, 30): '(0.5)', (35, 32, 35, 35): '(0.1)'}, {}), '(0, 0.5, 0.1)', True, 'import numpy as np\n'), ((36, 15, 36, 37), 'numpy.arange', 'np.arange', ({(36, 25, 36, 26): '(0)', (36, 28, 36, 31): '(0.5)', (36, 33, 36, 36): '(0.1)'}, {}), '(0, 0.5, 0.1)', True, 'import numpy as np\n'), ((39, 5, 39, 17), 'pyarrow.binary', 'pa.binary', ({(39, 15, 39, 16): '(3)'}, {}), '(3)', True, 'import pyarrow as pa\n'), ((63, 11, 63, 30), 'pyarrow.compute.sum', 'pa.compute.sum', ({(63, 26, 63, 29): 'arr'}, {}), '(arr)', True, 'import pyarrow as pa\n'), ((67, 11, 67, 30), 'pyarrow.compute.sum', 'pa.compute.sum', ({(67, 26, 67, 29): 'arr'}, {}), '(arr)', True, 'import pyarrow as pa\n'), ((73, 11, 73, 30), 'pyarrow.compute.sum', 'pa.compute.sum', ({(73, 26, 73, 29): 'arr'}, {}), '(arr)', True, 'import pyarrow as pa\n'), ((78, 11, 78, 30), 'pyarrow.compute.sum', 'pa.compute.sum', ({(78, 26, 78, 29): 'arr'}, {}), '(arr)', True, 'import pyarrow as pa\n'), ((85, 11, 85, 30), 'pyarrow.compute.sum', 'pa.compute.sum', ({(85, 26, 85, 29): 'arr'}, {}), '(arr)', True, 'import pyarrow as pa\n'), ((90, 11, 90, 30), 'pyarrow.compute.sum', 'pa.compute.sum', ({(90, 26, 90, 29): 'arr'}, {}), '(arr)', True, 'import pyarrow as pa\n'), ((96, 25, 96, 34), 'pyarrow.int8', 'pa.int8', ({}, {}), '()', True, 'import pyarrow as pa\n'), ((96, 36, 96, 46), 'pyarrow.int64', 'pa.int64', ({}, {}), '()', True, 'import pyarrow as pa\n'), ((97, 18, 97, 62), 'pyarrow.array', 'pa.array', (), '', True, 'import pyarrow as pa\n'), ((100, 19, 100, 77), 'pyarrow.array', 'pa.array', (), '', True, 'import pyarrow as pa\n'), ((104, 18, 104, 49), 'pyarrow.array', 'pa.array', (), '', True, 'import pyarrow as pa\n'), ((107, 19, 107, 40), 'pyarrow.array', 'pa.array', (), '', True, 'import pyarrow as pa\n'), ((111, 9, 111, 34), 'pytest.raises', 'pytest.raises', ({(111, 23, 111, 33): 'IndexError'}, {}), '(IndexError)', False, 'import pytest\n'), ((115, 9, 115, 34), 'pytest.raises', 'pytest.raises', ({(115, 23, 115, 33): 'IndexError'}, {}), '(IndexError)', False, 'import pytest\n'), ((124, 18, 124, 62), 'pyarrow.array', 'pa.array', (), '', True, 'import pyarrow as pa\n'), ((127, 19, 127, 44), 'pyarrow.array', 'pa.array', ({(127, 28, 127, 43): '[0, 4, 2, None]'}, {}), '([0, 4, 2, None])', True, 'import pyarrow as pa\n'), ((130, 25, 130, 37), 'pyarrow.float32', 'pa.float32', ({}, {}), '()', True, 'import pyarrow as pa\n'), ((130, 39, 130, 51), 'pyarrow.float64', 'pa.float64', ({}, {}), '()', True, 'import pyarrow as pa\n'), ((131, 18, 131, 56), 'pyarrow.array', 'pa.array', (), '', True, 'import pyarrow as pa\n'), ((140, 22, 140, 41), 'pyarrow.array', 'pa.array', ({(140, 31, 140, 40): '[0, 1, 3]'}, {}), '([0, 1, 3])', True, 'import pyarrow as pa\n'), ((154, 25, 154, 66), 'pyarrow.array', 'pa.array', (), '', True, 'import pyarrow as pa\n'), ((157, 25, 157, 72), 'pyarrow.array', 'pa.array', (), '', True, 'import pyarrow as pa\n'), ((161, 9, 161, 43), 'pytest.raises', 'pytest.raises', ({(161, 23, 161, 42): 'NotImplementedError'}, {}), '(NotImplementedError)', False, 'import pytest\n'), ((166, 9, 166, 71), 'pytest.raises', 'pytest.raises', (), '', False, 'import pytest\n'), ((177, 8, 177, 50), 'pyarrow.array', 'pa.array', ({(177, 17, 177, 49): '[True, False, None, False, True]'}, {}), '([True, False, None, False, True])', True, 'import pyarrow as pa\n'), ((179, 8, 179, 62), 'pyarrow.chunked_array', 'pa.chunked_array', ({(179, 25, 179, 61): '[[True, False, None], [False, True]]'}, {}), '([[True, False, None], [False, True]])', True, 'import pyarrow as pa\n'), ((211, 8, 211, 50), 'pyarrow.array', 'pa.array', ({(211, 17, 211, 49): '[True, False, None, False, True]'}, {}), '([True, False, None, False, True])', True, 'import pyarrow as pa\n'), ((213, 8, 213, 62), 'pyarrow.chunked_array', 'pa.chunked_array', ({(213, 25, 213, 61): '[[True, False], [None, False, True]]'}, {}), '([[True, False], [None, False, True]])', True, 'import pyarrow as pa\n'), ((231, 15, 231, 40), 'pyarrow.array', 'pa.array', ({(231, 24, 231, 39): '[0, 1, 0, 1, 0]'}, {}), '([0, 1, 0, 1, 0])', True, 'import pyarrow as pa\n'), ((236, 15, 236, 44), 'pyarrow.array', 'pa.array', ({(236, 24, 236, 43): '[True, False, True]'}, {}), '([True, False, True])', True, 'import pyarrow as pa\n'), ((40, 14, 40, 23), 'pyarrow.int8', 'pa.int8', ({}, {}), '()', True, 'import pyarrow as pa\n'), ((41, 19, 41, 29), 'pyarrow.int16', 'pa.int16', ({}, {}), '()', True, 'import pyarrow as pa\n'), ((72, 28, 72, 67), 'pyarrow.array', 'pa.array', (), '', True, 'import pyarrow as pa\n'), ((76, 8, 76, 41), 'pyarrow.array', 'pa.array', (), '', True, 'import pyarrow as pa\n'), ((76, 43, 76, 76), 'pyarrow.array', 'pa.array', (), '', True, 'import pyarrow as pa\n'), ((81, 8, 81, 41), 'pyarrow.array', 'pa.array', (), '', True, 'import pyarrow as pa\n'), ((82, 8, 82, 37), 'pyarrow.array', 'pa.array', (), '', True, 'import pyarrow as pa\n'), ((83, 8, 83, 41), 'pyarrow.array', 'pa.array', (), '', True, 'import pyarrow as pa\n'), ((132, 13, 132, 47), 'pytest.raises', 'pytest.raises', ({(132, 27, 132, 46): 'NotImplementedError'}, {}), '(NotImplementedError)', False, 'import pytest\n'), ((191, 9, 191, 45), 'pyarrow.array', 'pa.array', ({(191, 18, 191, 44): "['a', None, 'c', 'd', 'e']"}, {}), "(['a', None, 'c', 'd', 'e'])", True, 'import pyarrow as pa\n'), ((196, 32, 196, 52), 'pyarrow.array', 'pa.array', ({(196, 41, 196, 51): "['a', 'e']"}, {}), "(['a', 'e'])", True, 'import pyarrow as pa\n'), ((200, 32, 200, 58), 'pyarrow.array', 'pa.array', ({(200, 41, 200, 57): "['a', None, 'e']"}, {}), "(['a', None, 'e'])", True, 'import pyarrow as pa\n'), ((205, 22, 205, 58), 'pyarrow.array', 'pa.array', ({(205, 31, 205, 57): "['a', None, 'c', 'd', 'e']"}, {}), "(['a', None, 'c', 'd', 'e'])", True, 'import pyarrow as pa\n'), ((206, 30, 206, 50), 'pyarrow.array', 'pa.array', ({(206, 39, 206, 49): "['a', 'e']"}, {}), "(['a', 'e'])", True, 'import pyarrow as pa\n'), ((207, 30, 207, 56), 'pyarrow.array', 'pa.array', ({(207, 39, 207, 55): "['a', None, 'e']"}, {}), "(['a', None, 'e'])", True, 'import pyarrow as pa\n'), ((226, 9, 226, 45), 'pyarrow.array', 'pa.array', ({(226, 18, 226, 44): "['a', None, 'c', 'd', 'e']"}, {}), "(['a', None, 'c', 'd', 'e'])", True, 'import pyarrow as pa\n'), ((227, 22, 227, 58), 'pyarrow.array', 'pa.array', ({(227, 31, 227, 57): "['a', None, 'c', 'd', 'e']"}, {}), "(['a', None, 'c', 'd', 'e'])", True, 'import pyarrow as pa\n'), ((232, 13, 232, 47), 'pytest.raises', 'pytest.raises', ({(232, 27, 232, 46): 'NotImplementedError'}, {}), '(NotImplementedError)', False, 'import pytest\n'), ((237, 13, 238, 63), 'pytest.raises', 'pytest.raises', (), '', False, 'import pytest\n'), ((245, 32, 245, 48), 'pyarrow.array', 'pa.array', ({(245, 41, 245, 47): 'values'}, {}), '(values)', True, 'import pyarrow as pa\n'), ((247, 32, 247, 58), 'pyarrow.chunked_array', 'pa.chunked_array', ({(247, 49, 247, 57): '[values]'}, {}), '([values])', True, 'import pyarrow as pa\n'), ((274, 32, 274, 48), 'pyarrow.array', 'pa.array', ({(274, 41, 274, 47): 'values'}, {}), '(values)', True, 'import pyarrow as pa\n'), ((276, 32, 276, 58), 'pyarrow.chunked_array', 'pa.chunked_array', ({(276, 49, 276, 57): '[values]'}, {}), '([values])', True, 'import pyarrow as pa\n'), ((280, 13, 280, 26), 'pyarrow.array', 'pa.array', ({(280, 22, 280, 25): '[2]'}, {}), '([2])', True, 'import pyarrow as pa\n'), ((42, 22, 42, 31), 'pyarrow.int8', 'pa.int8', ({}, {}), '()', True, 'import pyarrow as pa\n'), ((42, 40, 42, 49), 'pyarrow.int8', 'pa.int8', ({}, {}), '()', True, 'import pyarrow as pa\n')]