Skip to content

Commit 3d1cb46

Browse files
committed
modified the files according to bug#60237
1 parent 6bcd303 commit 3d1cb46

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

doc/source/whatsnew/v3.0.0.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff 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

672673
Strings
673674
^^^^^^^

pandas/core/dtypes/cast.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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

pandas/tests/extension/test_arrow.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff 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)

0 commit comments

Comments
 (0)