apache / arrow

Apache Arrow is a multi-language toolbox for accelerated data interchange and in-memory processing
https://arrow.apache.org/
Apache License 2.0
14.31k stars 3.48k forks source link

[Python] array constructor ignore time zone in `type` #37342

Open MarcoGorelli opened 1 year ago

MarcoGorelli commented 1 year ago

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

In [16]: pa.array([datetime(2020, 1, 1, tzinfo=timezone(timedelta(hours=-8)))], type=pa.timestamp('us', 'US/Pacific'))
Out[16]:
<pyarrow.lib.TimestampArray object at 0x7fb4b56b93c0>
[
  2020-01-01 08:00:00.000000
]

In [17]: pa.array([datetime(2020, 1, 1, tzinfo=timezone(timedelta(hours=-8)))], type=pa.timestamp('us', 'UTC'))
Out[17]:
<pyarrow.lib.TimestampArray object at 0x7fb4b51426e0>
[
  2020-01-01 08:00:00.000000
]

In [18]: pa.array([datetime(2020, 1, 1)], type=pa.timestamp('us', 'US/Pacific'))
Out[18]:
<pyarrow.lib.TimestampArray object at 0x7fb4b5142500>
[
  2020-01-01 00:00:00.000000
]

Note how the result doesn't depend on the time zone I put in the type argument

Is this intentional? I'm not saying it's a bug or that it needs to change, it just came up in Polars: https://github.com/pola-rs/polars/issues/10662 - I just want to make sure that if there is any change, then we all go towards the same direction

versions:

Component(s)

Python

mapleFU commented 1 year ago

This looks a bit like https://github.com/apache/arrow/issues/37110