Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion python/pyarrow/array.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -901,7 +901,16 @@ cdef class Array(_PandasConvertible):
with nogil:
check_status(ConvertArrayToPandas(c_options, self.sp_array,
self, &out))
return pandas_api.series(wrap_array_output(out), name=self._name)
result = pandas_api.series(wrap_array_output(out), name=self._name)

if isinstance(self.type, TimestampType):
tz = self.type.tz
if tz is not None:
tz = string_to_tzinfo(tz)
result = (result.dt.tz_localize('utc')
.dt.tz_convert(tz))

return result

def __array__(self, dtype=None):
cdef:
Expand Down
8 changes: 8 additions & 0 deletions python/pyarrow/tests/test_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -1778,3 +1778,11 @@ def test_concat_array():
def test_concat_array_different_types():
with pytest.raises(pa.ArrowInvalid):
pa.concat_arrays([pa.array([1]), pa.array([2.])])


@pytest.mark.pandas
def test_to_pandas_timezone():
# https://issues.apache.org/jira/browse/ARROW-6652
arr = pa.array([1, 2, 3], type=pa.timestamp('s', tz='Europe/Brussels'))
s = arr.to_pandas()
assert s.dt.tz is not None
4 changes: 0 additions & 4 deletions python/pyarrow/tests/test_pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,6 @@ def _check_series_roundtrip(s, type_=None, expected_pa_type=None):
assert arr.type == expected_pa_type

result = pd.Series(arr.to_pandas(), name=s.name)
if pa.types.is_timestamp(arr.type) and arr.type.tz is not None:
result = (result.dt.tz_localize('utc')
.dt.tz_convert(arr.type.tz))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The series roundtrip with timezone was actually already tested in this file, but this fixup of the result was masking the issue. So before, it was expected that Array.to_pandas would loose the timezone (maybe because this method could also return numpy arrays in some cases). But I don't see a reason to not keep it (certainly now it always returns Series, and now Column is gone, which retained the timezone)


tm.assert_series_equal(s, result)


Expand Down