Skip to content

Backport PR #55072 on branch 2.1.x (BUG: dt.tz with ArrowDtype returned string) #55124

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
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
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