File tree Expand file tree Collapse file tree 3 files changed +26
-1
lines changed Expand file tree Collapse file tree 3 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -668,6 +668,7 @@ Conversion
668
668
- Bug in :meth: `DataFrame.update ` bool dtype being converted to object (:issue: `55509 `)
669
669
- Bug in :meth: `Series.astype ` might modify read-only array inplace when casting to a string dtype (:issue: `57212 `)
670
670
- Bug in :meth: `Series.reindex ` not maintaining ``float32 `` type when a ``reindex `` introduces a missing value (:issue: `45857 `)
671
+ - Bug in :meth: `convert_dtypes ` not preserving timezone details for ArrowDtype in Series and DataFrame (:issue: `60237 `)
671
672
672
673
Strings
673
674
^^^^^^^
Original file line number Diff line number Diff line change @@ -1113,7 +1113,7 @@ def convert_dtypes(
1113
1113
else :
1114
1114
inferred_dtype = input_array .dtype
1115
1115
1116
- if dtype_backend == "pyarrow" :
1116
+ if dtype_backend == "pyarrow" and not isinstance ( inferred_dtype , ArrowDtype ) :
1117
1117
from pandas .core .arrays .arrow .array import to_pyarrow_type
1118
1118
from pandas .core .arrays .string_ import StringDtype
1119
1119
Original file line number Diff line number Diff line change @@ -3511,3 +3511,27 @@ def test_map_numeric_na_action():
3511
3511
result = ser .map (lambda x : 42 , na_action = "ignore" )
3512
3512
expected = pd .Series ([42.0 , 42.0 , np .nan ], dtype = "float64" )
3513
3513
tm .assert_series_equal (result , expected )
3514
+
3515
+
3516
+ def test_convert_dtype_pyarrow_timezone_preserve ():
3517
+ # GH 60237
3518
+ pytest .importorskip ("pyarrow" )
3519
+ ser = pd .Series (
3520
+ pd .to_datetime (range (5 ), utc = True , unit = "h" ),
3521
+ dtype = "timestamp[ns, tz=UTC][pyarrow]" ,
3522
+ )
3523
+ result = ser .convert_dtypes (dtype_backend = "pyarrow" )
3524
+ expected = ser .copy ()
3525
+ tm .assert_series_equal (result , expected )
3526
+
3527
+ df = pd .DataFrame (
3528
+ {
3529
+ "timestamps" : pd .Series (
3530
+ pd .to_datetime (range (5 ), utc = True , unit = "h" ),
3531
+ dtype = "timestamp[ns, tz=UTC][pyarrow]" ,
3532
+ )
3533
+ }
3534
+ )
3535
+ result = df .convert_dtypes (dtype_backend = "pyarrow" )
3536
+ expected = df .copy ()
3537
+ tm .assert_frame_equal (result , expected )
You can’t perform that action at this time.
0 commit comments