Skip to content

[Python][C++][Compute] Integer round crashes for uint64 with ndigits=-19 and gives wrong half-rounding for large multiples #55908

Backlog

Description

@lance-lii

Describe the bug, including details regarding any error messages, version, and platform.

round / round_binary on uint64 with ndigits=-19 crash the process, and round_to_multiple
on integers returns wrong results in the HALF_* modes when the multiple is larger than half the
type's maximum.

import pyarrow as pa, pyarrow.compute as pc

pc.round(pa.array([6], pa.uint64()), -19)
# Floating point exception (core dumped)   expected [0]; -20 correctly raises "out of range"

M = 2**63 - 1
pc.round_to_multiple(pa.array([3 * 2**61]), multiple=pa.scalar(M), round_mode="half_up")
# [0]   expected [9223372036854775807]
pc.round_to_multiple(pa.array([3_000_000_000], pa.uint32()),
                     multiple=pa.scalar(4_000_000_000, pa.uint32()), round_mode="half_up")
# [0]   expected [4000000000]

Causes, in cpp/src/arrow/compute/kernels/scalar_round.cc:

  • the ndigits range check allows up to digits10 (19 for uint64), but the integer RoundUtil::Pow10
    table stops at 10^18, so lut[19] is read past the end (0 in release builds -> division by zero).
  • RoundToMultiple<integer> compares remainder * 2 with multiple, which overflows when
    multiple > max / 2.

I ran into this while testing integer rounding at the edges of each type's range, and the uint64 case taking down the whole Python process rather than raising an error is what made me dig in.

Reproduced on main (52d252f) and pyarrow 27.0.0.dev204 nightly, Linux x86_64, Python 3.13.
I have a small fix with tests (add 10^19 to the table; compare remainder against
multiple - remainder) and can open a PR.

This issue was drafted with help from an AI assistant and checked by me.

Component(s)

C++, Python

Activity

  1. changed the title [-][C++][Compute] Integer round crashes for uint64 with ndigits=-19 and gives wrong half-rounding for large multiples[/-] [+][Python][C++][Compute] Integer round crashes for uint64 with ndigits=-19 and gives wrong half-rounding for large multiples[/+] on Dec 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions