MCPcopy Create free account
hub / github.com/apache/arrow / test_cumulative_max

Function test_cumulative_max

python/pyarrow/tests/test_compute.py:3680–3732  ·  view source on GitHub ↗
(start, skip_nulls)

Source from the content-addressed store, hash-verified

3678@pytest.mark.parametrize('start', (0.5, 3.5, 6.5))
3679@pytest.mark.parametrize('skip_nulls', (True, False))
3680def test_cumulative_max(start, skip_nulls):
3681 # Exact tests (e.g., integral types)
3682 start_int = int(start)
3683 starts = [None, start_int, pa.scalar(start_int, type=pa.int8()),
3684 pa.scalar(start_int, type=pa.int64())]
3685 for strt in starts:
3686 arrays = [
3687 pa.array([2, 1, 3, 5, 4, 6]),
3688 pa.array([2, 1, None, 5, 4, None]),
3689 pa.chunked_array([[2, 1, None], [5, 4, None]])
3690 ]
3691 expected_arrays = [
3692 pa.array([2, 2, 3, 5, 5, 6]),
3693 pa.array([2, 2, None, 5, 5, None])
3694 if skip_nulls else pa.array([2, 2, None, None, None, None]),
3695 pa.chunked_array([[2, 2, None, 5, 5, None]])
3696 if skip_nulls else
3697 pa.chunked_array([[2, 2, None, None, None, None]])
3698 ]
3699 for i, arr in enumerate(arrays):
3700 result = pc.cumulative_max(arr, start=strt, skip_nulls=skip_nulls)
3701 # Max `start` offset with expected array before comparing
3702 expected = pc.max_element_wise(
3703 expected_arrays[i], strt if strt is not None else int(-1e9),
3704 skip_nulls=False)
3705 assert result.equals(expected)
3706
3707 starts = [None, start, pa.scalar(start, type=pa.float32()),
3708 pa.scalar(start, type=pa.float64())]
3709 for strt in starts:
3710 arrays = [
3711 pa.array([2.5, 1.3, 3.7, 5.1, 4.9, 6.2]),
3712 pa.array([2.5, 1.3, 3.7, np.nan, 4.9, 6.2]),
3713 pa.array([2.5, 1.3, None, np.nan, 4.9, None])
3714 ]
3715 expected_arrays = [
3716 np.array([2.5, 2.5, 3.7, 5.1, 5.1, 6.2]),
3717 np.array([2.5, 2.5, 3.7, 3.7, 4.9, 6.2]),
3718 np.array([2.5, 2.5, None, 2.5, 4.9, None])
3719 if skip_nulls else np.array([2.5, 2.5, None, None, None, None])
3720 ]
3721 for i, arr in enumerate(arrays):
3722 result = pc.cumulative_max(arr, start=strt, skip_nulls=skip_nulls)
3723 # Max `start` offset with expected array before comparing
3724 expected = pc.max_element_wise(
3725 expected_arrays[i], strt if strt is not None else -1e9,
3726 skip_nulls=False)
3727 np.testing.assert_array_almost_equal(result.to_numpy(
3728 zero_copy_only=False), expected.to_numpy(zero_copy_only=False))
3729
3730 for strt in ['a', pa.scalar('arrow'), 1.1]:
3731 with pytest.raises(pa.ArrowInvalid):
3732 pc.cumulative_max([1, 2, 3], start=strt)
3733
3734
3735@pytest.mark.numpy

Callers

nothing calls this directly

Calls 4

chunked_arrayMethod · 0.80
equalsMethod · 0.80
scalarMethod · 0.45
arrayMethod · 0.45

Tested by

no test coverage detected