Skip to content

Commit 712b2f6

Browse files
authored
BUG: Fix tz_localize(None) with Arrow timestamp (#62076)
1 parent 7863029 commit 712b2f6

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed

doc/source/whatsnew/v3.0.0.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -732,6 +732,7 @@ Timedelta
732732
Timezones
733733
^^^^^^^^^
734734
- Bug in :meth:`DatetimeIndex.union`, :meth:`DatetimeIndex.intersection`, and :meth:`DatetimeIndex.symmetric_difference` changing timezone to UTC when merging two DatetimeIndex objects with the same timezone but different units (:issue:`60080`)
735+
- Bug in :meth:`Series.dt.tz_localize` with a timezone-aware :class:`ArrowDtype` incorrectly converting to UTC when ``tz=None`` (:issue:`61780`)
735736
-
736737

737738
Numeric

pandas/core/arrays/arrow/array.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2953,7 +2953,7 @@ def _dt_tz_localize(
29532953
if nonexistent_pa is None:
29542954
raise NotImplementedError(f"{nonexistent=} is not supported")
29552955
if tz is None:
2956-
result = self._pa_array.cast(pa.timestamp(self.dtype.pyarrow_dtype.unit))
2956+
result = pc.local_timestamp(self._pa_array)
29572957
else:
29582958
result = pc.assume_timezone(
29592959
self._pa_array, str(tz), ambiguous=ambiguous, nonexistent=nonexistent_pa

pandas/tests/extension/test_arrow.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2679,8 +2679,9 @@ def test_dt_tz_localize_unsupported_tz_options():
26792679
ser.dt.tz_localize("UTC", nonexistent="NaT")
26802680

26812681

2682-
@pytest.mark.xfail(reason="Converts to UTC before localizing GH#61780")
2683-
def test_dt_tz_localize_none():
2682+
def test_dt_tz_localize_none(request):
2683+
_require_timezone_database(request)
2684+
26842685
ser = pd.Series(
26852686
[datetime(year=2023, month=1, day=2, hour=3), None],
26862687
dtype=ArrowDtype(pa.timestamp("ns", tz="US/Pacific")),

0 commit comments

Comments
 (0)