rok commented on issue #48003:
URL: https://github.com/apache/arrow/issues/48003#issuecomment-3473306119
Thanks for compiling the list in #39233, it is useful to see!
I suppose the issue you're describing occurs because multiplying double with
`duration[xs]` would need to return a `duration[xs]`, which would requires an
implicit rounding step (`duration[xs]` is physically an `int64`). We can
discuss adding this as implicit logic, but we try to avoid implicit steps like
this. You can work around this by adding a round step:
```python
import pyarrow as pa
deltas = pa.array([1, 2, 3], type=pa.duration("s"))
unit = pa.scalar(1, type=pa.duration("s"))
# forward transform to float:
x = pa.compute.divide(deltas, unit) # gives double
# added rounding step
x = pc.compute.round(x, unit.value).cast("int64") # This won't work if unit
is not an integer
# backward transform to duration
y = pa.compute.multiply(x, unit)
```
But are you doing temporal rounding?
```math
\frac{timestamp - reference}{unit} * unit + reference
```
If so you can try:
```python
import pyarrow as pa
timestamps = pa.array([1, 2, 3], type=pa.timestamp("s"))
durations = pa.array([1, 2, 3], type=pa.duration("s"))
y = pa.compute.round_temporal(timestamps, unit="second", multiple=1) # We
should have this work on durations too
```
Or go unitless:
```python
import pyarrow as pa
durations = pa.array([1, 2, 3], type=pa.duration("s"))
y = pa.compute.round_to_multiple(durations.cast("int64"), 1)
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]