diff --git a/python/pyarrow/array.pxi b/python/pyarrow/array.pxi index e47327ff2d4e2..e35717d742415 100644 --- a/python/pyarrow/array.pxi +++ b/python/pyarrow/array.pxi @@ -903,12 +903,10 @@ cdef class Array(_PandasConvertible): self, &out)) 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)) + if isinstance(self.type, TimestampType) and self.type.tz is not None: + from pyarrow.pandas_compat import make_tz_aware + + result = make_tz_aware(result, self.type.tz) return result diff --git a/python/pyarrow/pandas_compat.py b/python/pyarrow/pandas_compat.py index 4b7e2e0298756..900711ab6bda9 100644 --- a/python/pyarrow/pandas_compat.py +++ b/python/pyarrow/pandas_compat.py @@ -1046,3 +1046,17 @@ def _add_any_metadata(table, pandas_metadata): return pa.Table.from_arrays(columns, schema=pa.schema(fields)) else: return table + + +# ---------------------------------------------------------------------- +# Helper functions used in lib + + +def make_tz_aware(series, tz): + """ + Make a datetime64 Series timezone-aware for the given tz + """ + tz = pa.lib.string_to_tzinfo(tz) + series = (series.dt.tz_localize('utc') + .dt.tz_convert(tz)) + return series diff --git a/python/pyarrow/table.pxi b/python/pyarrow/table.pxi index 8a8edd88b47e9..086c4f45011ee 100644 --- a/python/pyarrow/table.pxi +++ b/python/pyarrow/table.pxi @@ -165,12 +165,10 @@ cdef class ChunkedArray(_PandasConvertible): 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)) + if isinstance(self.type, TimestampType) and self.type.tz is not None: + from pyarrow.pandas_compat import make_tz_aware + + result = make_tz_aware(result, self.type.tz) return result