()
| 2011 | |
| 2012 | @pytest.mark.numpy |
| 2013 | def test_round_to_multiple(): |
| 2014 | values = [320, 3.5, 3.075, 4.5, -3.212, -35.1234, -3.045, None] |
| 2015 | multiple_and_expected = { |
| 2016 | 0.05: [320, 3.5, 3.1, 4.5, -3.2, -35.1, -3.05, None], |
| 2017 | pa.scalar(0.1): [320, 3.5, 3.1, 4.5, -3.2, -35.1, -3, None], |
| 2018 | 2: [320, 4, 4, 4, -4, -36, -4, None], |
| 2019 | 10: [320, 0, 0, 0, -0, -40, -0, None], |
| 2020 | pa.scalar(100, type=pa.decimal256(10, 4)): |
| 2021 | [300, 0, 0, 0, -0, -0, -0, None], |
| 2022 | } |
| 2023 | for multiple, expected in multiple_and_expected.items(): |
| 2024 | options = pc.RoundToMultipleOptions(multiple, "half_towards_infinity") |
| 2025 | result = pc.round_to_multiple(values, options=options) |
| 2026 | np.testing.assert_allclose(result, pa.array(expected), equal_nan=True) |
| 2027 | assert pc.round_to_multiple(values, multiple, |
| 2028 | "half_towards_infinity") == result |
| 2029 | |
| 2030 | for multiple in [0, -2, pa.scalar(-10.4)]: |
| 2031 | with pytest.raises(pa.ArrowInvalid, |
| 2032 | match="Rounding multiple must be positive"): |
| 2033 | pc.round_to_multiple(values, multiple=multiple) |
| 2034 | |
| 2035 | for multiple in [object, 99999999999999999999999]: |
| 2036 | with pytest.raises(TypeError, match="is not a valid multiple type"): |
| 2037 | pc.round_to_multiple(values, multiple=multiple) |
| 2038 | |
| 2039 | |
| 2040 | def test_round_binary(): |
nothing calls this directly
no test coverage detected