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

Function test_quantile

python/pyarrow/tests/test_compute.py:3465–3505  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

3463
3464
3465def test_quantile():
3466 arr = pa.array([1, 2, 3, 4])
3467
3468 result = pc.quantile(arr)
3469 assert result.to_pylist() == [2.5]
3470
3471 result = pc.quantile(arr, interpolation='lower')
3472 assert result.to_pylist() == [2]
3473 result = pc.quantile(arr, interpolation='higher')
3474 assert result.to_pylist() == [3]
3475 result = pc.quantile(arr, interpolation='nearest')
3476 assert result.to_pylist() == [3]
3477 result = pc.quantile(arr, interpolation='midpoint')
3478 assert result.to_pylist() == [2.5]
3479 result = pc.quantile(arr, interpolation='linear')
3480 assert result.to_pylist() == [2.5]
3481
3482 arr = pa.array([1, 2])
3483
3484 result = pc.quantile(arr, q=[0.25, 0.5, 0.75])
3485 assert result.to_pylist() == [1.25, 1.5, 1.75]
3486
3487 result = pc.quantile(arr, q=[0.25, 0.5, 0.75], interpolation='lower')
3488 assert result.to_pylist() == [1, 1, 1]
3489 result = pc.quantile(arr, q=[0.25, 0.5, 0.75], interpolation='higher')
3490 assert result.to_pylist() == [2, 2, 2]
3491 result = pc.quantile(arr, q=[0.25, 0.5, 0.75], interpolation='midpoint')
3492 assert result.to_pylist() == [1.5, 1.5, 1.5]
3493 result = pc.quantile(arr, q=[0.25, 0.5, 0.75], interpolation='nearest')
3494 assert result.to_pylist() == [1, 1, 2]
3495 result = pc.quantile(arr, q=[0.25, 0.5, 0.75], interpolation='linear')
3496 assert result.to_pylist() == [1.25, 1.5, 1.75]
3497
3498 # Positional `q`
3499 result = pc.quantile(arr, [0.25, 0.5, 0.75], interpolation='linear')
3500 assert result.to_pylist() == [1.25, 1.5, 1.75]
3501
3502 with pytest.raises(ValueError, match="Quantile must be between 0 and 1"):
3503 pc.quantile(arr, q=1.1)
3504 with pytest.raises(ValueError, match="not a valid quantile interpolation"):
3505 pc.quantile(arr, interpolation='zzz')
3506
3507
3508def test_tdigest():

Callers

nothing calls this directly

Calls 1

arrayMethod · 0.45

Tested by

no test coverage detected