Skip to content

Commit 0cc87ee

Browse files
Backport PR #55072 on branch 2.1.x (BUG: dt.tz with ArrowDtype returned string) (#55124)
Backport PR #55072: BUG: dt.tz with ArrowDtype returned string Co-authored-by: Matthew Roeschke <[email protected]>
1 parent 4f5cd87 commit 0cc87ee

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

doc/source/whatsnew/v2.1.1.rst

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ Bug fixes
3535
~~~~~~~~~
3636
- Fixed bug for :class:`ArrowDtype` raising ``NotImplementedError`` for fixed-size list (:issue:`55000`)
3737
- Fixed bug in :meth:`DataFrame.stack` with ``future_stack=True`` and columns a non-:class:`MultiIndex` consisting of tuples (:issue:`54948`)
38+
- Fixed bug in :meth:`Series.dt.tz` with :class:`ArrowDtype` where a string was returned instead of a ``tzinfo`` object (:issue:`55003`)
3839
- Fixed bug in :meth:`Series.pct_change` and :meth:`DataFrame.pct_change` showing unnecessary ``FutureWarning`` (:issue:`54981`)
3940

4041
.. ---------------------------------------------------------------------------

pandas/core/arrays/arrow/array.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from pandas._libs.tslibs import (
1919
Timedelta,
2020
Timestamp,
21+
timezones,
2122
)
2223
from pandas.compat import (
2324
pa_version_under7p0,
@@ -2421,7 +2422,7 @@ def _dt_time(self):
24212422

24222423
@property
24232424
def _dt_tz(self):
2424-
return self.dtype.pyarrow_dtype.tz
2425+
return timezones.maybe_get_tz(self.dtype.pyarrow_dtype.tz)
24252426

24262427
@property
24272428
def _dt_unit(self):

pandas/tests/extension/test_arrow.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import pytest
3232

3333
from pandas._libs import lib
34+
from pandas._libs.tslibs import timezones
3435
from pandas.compat import (
3536
PY311,
3637
is_ci_environment,
@@ -2477,7 +2478,7 @@ def test_dt_tz(tz):
24772478
dtype=ArrowDtype(pa.timestamp("ns", tz=tz)),
24782479
)
24792480
result = ser.dt.tz
2480-
assert result == tz
2481+
assert result == timezones.maybe_get_tz(tz)
24812482

24822483

24832484
def test_dt_isocalendar():

0 commit comments

Comments
 (0)