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

Function test_cumulative_min

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

Source from the content-addressed store, hash-verified

3758@pytest.mark.parametrize('start', (0.5, 3.5, 6.5))
3759@pytest.mark.parametrize('skip_nulls', (True, False))
3760def test_cumulative_min(start, skip_nulls):
3761 # Exact tests (e.g., integral types)
3762 start_int = int(start)
3763 starts = [None, start_int, pa.scalar(start_int, type=pa.int8()),
3764 pa.scalar(start_int, type=pa.int64())]
3765 for strt in starts:
3766 arrays = [
3767 pa.array([5, 6, 4, 2, 3, 1]),
3768 pa.array([5, 6, None, 2, 3, None]),
3769 pa.chunked_array([[5, 6, None], [2, 3, None]])
3770 ]
3771 expected_arrays = [
3772 pa.array([5, 5, 4, 2, 2, 1]),
3773 pa.array([5, 5, None, 2, 2, None])
3774 if skip_nulls else pa.array([5, 5, None, None, None, None]),
3775 pa.chunked_array([[5, 5, None, 2, 2, None]])
3776 if skip_nulls else
3777 pa.chunked_array([[5, 5, None, None, None, None]])
3778 ]
3779 for i, arr in enumerate(arrays):
3780 result = pc.cumulative_min(arr, start=strt, skip_nulls=skip_nulls)
3781 # Min `start` offset with expected array before comparing
3782 expected = pc.min_element_wise(
3783 expected_arrays[i], strt if strt is not None else int(1e9),
3784 skip_nulls=False)
3785 assert result.equals(expected)
3786
3787 starts = [None, start, pa.scalar(start, type=pa.float32()),
3788 pa.scalar(start, type=pa.float64())]
3789 for strt in starts:
3790 arrays = [
3791 pa.array([5.5, 6.3, 4.7, 2.1, 3.9, 1.2]),
3792 pa.array([5.5, 6.3, 4.7, np.nan, 3.9, 1.2]),
3793 pa.array([5.5, 6.3, None, np.nan, 3.9, None])
3794 ]
3795 expected_arrays = [
3796 np.array([5.5, 5.5, 4.7, 2.1, 2.1, 1.2]),
3797 np.array([5.5, 5.5, 4.7, 4.7, 3.9, 1.2]),
3798 np.array([5.5, 5.5, None, 5.5, 3.9, None])
3799 if skip_nulls else np.array([5.5, 5.5, None, None, None, None])
3800 ]
3801 for i, arr in enumerate(arrays):
3802 result = pc.cumulative_min(arr, start=strt, skip_nulls=skip_nulls)
3803 # Min `start` offset with expected array before comparing
3804 expected = pc.min_element_wise(
3805 expected_arrays[i], strt if strt is not None else 1e9,
3806 skip_nulls=False)
3807 np.testing.assert_array_almost_equal(result.to_numpy(
3808 zero_copy_only=False), expected.to_numpy(zero_copy_only=False))
3809
3810 for strt in ['a', pa.scalar('arrow'), 1.1]:
3811 with pytest.raises(pa.ArrowInvalid):
3812 pc.cumulative_max([1, 2, 3], start=strt)
3813
3814
3815def test_make_struct():

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