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
668668- Bug in :meth: `DataFrame.update ` bool dtype being converted to object (:issue: `55509 `)
669669- Bug in :meth: `Series.astype ` might modify read-only array inplace when casting to a string dtype (:issue: `57212 `)
670670- 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 `)
671672
672673Strings
673674^^^^^^^
Original file line number Diff line number Diff line change @@ -1113,7 +1113,7 @@ def convert_dtypes(
11131113 else :
11141114 inferred_dtype = input_array .dtype
11151115
1116- if dtype_backend == "pyarrow" :
1116+ if dtype_backend == "pyarrow" and not isinstance ( inferred_dtype , ArrowDtype ) :
11171117 from pandas .core .arrays .arrow .array import to_pyarrow_type
11181118 from pandas .core .arrays .string_ import StringDtype
11191119
Original file line number Diff line number Diff line change @@ -3511,3 +3511,27 @@ def test_map_numeric_na_action():
35113511 result = ser .map (lambda x : 42 , na_action = "ignore" )
35123512 expected = pd .Series ([42.0 , 42.0 , np .nan ], dtype = "float64" )
35133513 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