apache / apache/arrow

[C++][Python] Incorrect result for `floor_temporal` with 3 and 'year'

Open
#46,301 11 comments 0 reactions 0 assignees View on GitHub
Component: Python Type: bug
Dominant language
C++
Stars
17.1k
Forks
4.3k
Avg merge
3d 13h
Merged PRs (30d)
88

Description

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

```python
import pyarrow as pa
import pyarrow.compute as pc
import duckdb

print(duckdb.sql(
"""
from values (timestamp '1970-01-01') df(a)
select time_bucket('3 years', "a", timestamp '1970-01-01')
"""
))
print(pc.floor_temporal(pa.array([datetime(1970, 1, 1)]), 3, 'year'))
```
Outputs:
```
┌────────────────────────────────────────────────────────────┐
│ time_bucket('3 years', a, CAST('1970-01-01' AS TIMESTAMP)) │
│ timestamp │
├────────────────────────────────────────────────────────────┤
│ 1970-01-01 00:00:00 │
└────────────────────────────────────────────────────────────┘

[
1968-01-01 00:00:00.000000
]
```

The DuckDB output differs from the PyArrow one. Given that the pyarrow docs say

> By default, the origin is 1970-01-01T00:00:00.

I would expect it to be aligned with DuckDB when specifying `timestamp '1970-01-01'` as origin.

In fact, if I use `36, 'month'`, then PyArrow also returns `'1970-01-01'`. The fact that `3, 'year'` differs from `3*12, 'month'` suggests to me that there's a bug

```python
In [6]: pc.floor_temporal(arr, 3, 'year')
Out[6]:

[
1968-01-01 00:00:00.000000
]

In [7]: pc.floor_temporal(arr, 3*12, 'month')
Out[7]:

[
1970-01-01 00:00:00.000000
]
```

### Component(s)

Python

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.