You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[C++] Support "round" kernel for integer inputs #35273
Describe the bug, including details regarding any error messages, version, and platform.
In [11]: import pyarrow as pa
In [12]: pa.compute.round(pa.array([1372636858620000589]))
ArrowInvalid: Integer value 1372636858620000589 not in range: -9007199254740992 to 9007199254740992
In [13]: pa.__version__
Out[13]: '11.0.0'
Not sure why the rounding range is narrower (2^53) that the int64 range
And so for numeric types we do have some automatic type casting to find a kernel, which in this case doesn't really do what would be expected (the failure you see is from trying to cast int to float, and the int is too large to to be faithfully represented as a float).
So on the short term, I think pandas can just avoid calling the kernel on integers, as it should be a no-op anyway. And it might be more convenient that pyarrow adds a dummy kernel for the integer types as well.
So on the short term, I think pandas can just avoid calling the kernel on integers, as it should be a no-op anyway. And it might be more convenient that pyarrow adds a dummy kernel for the integer types as well.
Actually, rounding to a ndigits >= 0 is a no-op, but of course rounding to a negative ndigits is also useful for integers (and not a no-op):
In [23]: pa.compute.round([2023], ndigits=-1)
Out[23]:
<pyarrow.lib.DoubleArray object at 0x7ff8aa3b8b80>
[
2020
]
changed the title [-]BUG: pyarrow.compute.round fails for large integer within int64[/-][+][C++] Support "round" kernel for integer inputs[/+]on Apr 21, 2023
I've added good-second-issue as a label. Adding a new kernel is not trivial but it is rather self-contained. Someone could also use the existing round kernels as inspiration.
@jorisvandenbossche@westonpace While it would be meaningful to implement round and round_to_multiple kernels for integers, how about floor, ceil and trunc? These functions currently also cast ints to floats. If we do add kernels for ints, they will essentially be no-op. If we don't, then there will be inconsistency between them and round. Which way do you think would be better?
If we don't, then there will be inconsistency between them and round. Which way do you think would be better?
I don't think I would be opposed to dummy implementations but I don't think we need them. Planners are typically smart enough to recognize that these are no-ops and remove them.
Activity
jorisvandenbossche commentedon Apr 21, 2023
The issue here is that the "round" kernel is only implemented for floats / decimals:
And so for numeric types we do have some automatic type casting to find a kernel, which in this case doesn't really do what would be expected (the failure you see is from trying to cast int to float, and the int is too large to to be faithfully represented as a float).
So on the short term, I think pandas can just avoid calling the kernel on integers, as it should be a no-op anyway. And it might be more convenient that pyarrow adds a dummy kernel for the integer types as well.
jorisvandenbossche commentedon Apr 21, 2023
Actually, rounding to a
ndigits>= 0 is a no-op, but of course rounding to a negativendigitsis also useful for integers (and not a no-op):[-]BUG: pyarrow.compute.round fails for large integer within int64[/-][+][C++] Support "round" kernel for integer inputs[/+]westonpace commentedon Apr 26, 2023
I've added
good-second-issueas a label. Adding a new kernel is not trivial but it is rather self-contained. Someone could also use the existing round kernels as inspiration.westonpace commentedon Apr 26, 2023
#13933 would likely be useful for anyone new that is looking to author a kernel.
js8544 commentedon Jun 25, 2023
take
js8544 commentedon Jun 25, 2023
@jorisvandenbossche @westonpace While it would be meaningful to implement
roundandround_to_multiplekernels for integers, how aboutfloor,ceilandtrunc? These functions currently also cast ints to floats. If we do add kernels for ints, they will essentially be no-op. If we don't, then there will be inconsistency between them andround. Which way do you think would be better?westonpace commentedon Jun 29, 2023
I don't think I would be opposed to dummy implementations but I don't think we need them. Planners are typically smart enough to recognize that these are no-ops and remove them.
GH-35273: [C++] Add integer round kernels (#36289)
apacheGH-35273: [C++] Add integer round kernels (apache#36289)