apache / apache/arrow

[C++][Python] `cast` with timezone-aware array inconsistent when casting to `timestamp` and `date32`

Open
#46,738 1 comment 1 reaction 0 assignees View on GitHub
Component: C++ 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
from zoneinfo import ZoneInfo
from datetime import datetime

arr = pa.array([datetime(2020,1,1, tzinfo=ZoneInfo('Asia/Kathmandu'))])

print(pc.strftime(arr.cast(pa.timestamp('us')), '%Y-%m-%d'))
print(pc.strftime(arr.cast(pa.date32()), '%Y-%m-%d'))
```

This outputs:
```
[
"2019-12-31"
]
[
"2020-01-01"
]
```

So, when casting to `timestamp('us')`, it seems that PyArrow keeps the underlying timestamp the same but just reinterprets it in UTC

But when casting to date, it does it according to the local time zone

I don't know which one is right, but I'd have expected them to follow the same logic

### 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.