Skip to content

Commit

Permalink
Backport PR #55072 on branch 2.1.x (BUG: dt.tz with ArrowDtype return…
Browse files Browse the repository at this point in the history
…ed string) (#55124)

Backport PR #55072: BUG: dt.tz with ArrowDtype returned string

Co-authored-by: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com>
  • Loading branch information
meeseeksmachine and mroeschke committed Sep 13, 2023
1 parent 4f5cd87 commit 0cc87ee
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
1 change: 1 addition & 0 deletions doc/source/whatsnew/v2.1.1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Bug fixes
~~~~~~~~~
- Fixed bug for :class:`ArrowDtype` raising ``NotImplementedError`` for fixed-size list (:issue:`55000`)
- Fixed bug in :meth:`DataFrame.stack` with ``future_stack=True`` and columns a non-:class:`MultiIndex` consisting of tuples (:issue:`54948`)
- Fixed bug in :meth:`Series.dt.tz` with :class:`ArrowDtype` where a string was returned instead of a ``tzinfo`` object (:issue:`55003`)
- Fixed bug in :meth:`Series.pct_change` and :meth:`DataFrame.pct_change` showing unnecessary ``FutureWarning`` (:issue:`54981`)

.. ---------------------------------------------------------------------------
Expand Down
3 changes: 2 additions & 1 deletion pandas/core/arrays/arrow/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from pandas._libs.tslibs import (
Timedelta,
Timestamp,
timezones,
)
from pandas.compat import (
pa_version_under7p0,
Expand Down Expand Up @@ -2421,7 +2422,7 @@ def _dt_time(self):

@property
def _dt_tz(self):
return self.dtype.pyarrow_dtype.tz
return timezones.maybe_get_tz(self.dtype.pyarrow_dtype.tz)

@property
def _dt_unit(self):
Expand Down
3 changes: 2 additions & 1 deletion pandas/tests/extension/test_arrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import pytest

from pandas._libs import lib
from pandas._libs.tslibs import timezones
from pandas.compat import (
PY311,
is_ci_environment,
Expand Down Expand Up @@ -2477,7 +2478,7 @@ def test_dt_tz(tz):
dtype=ArrowDtype(pa.timestamp("ns", tz=tz)),
)
result = ser.dt.tz
assert result == tz
assert result == timezones.maybe_get_tz(tz)


def test_dt_isocalendar():
Expand Down

0 comments on commit 0cc87ee

Please sign in to comment.