Skip to content

Commit d3ed71e

Browse files
committed
BUG: fixed .convert_dtypes timezone strip from tz-aware pyarrow timestamp Series (#60237)
1 parent 5f23ace commit d3ed71e

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

doc/source/whatsnew/v3.0.0.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,7 @@ Conversion
649649
- Bug in :meth:`DataFrame.update` bool dtype being converted to object (:issue:`55509`)
650650
- Bug in :meth:`Series.astype` might modify read-only array inplace when casting to a string dtype (:issue:`57212`)
651651
- Bug in :meth:`Series.reindex` not maintaining ``float32`` type when a ``reindex`` introduces a missing value (:issue:`45857`)
652+
- Bug in :meth: 'Series.convert_dtype' strips the timezone on an already Timezone aware pyarrow timestamp dtype (:issue:'60237')
652653

653654
Strings
654655
^^^^^^^

pandas/core/dtypes/dtypes.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2277,18 +2277,6 @@ def name(self) -> str: # type: ignore[override]
22772277
@cache_readonly
22782278
def numpy_dtype(self) -> np.dtype:
22792279
"""Return an instance of the related numpy dtype"""
2280-
if pa.types.is_timestamp(self.pyarrow_dtype):
2281-
# pa.timestamp(unit).to_pandas_dtype() returns ns units
2282-
# regardless of the pyarrow timestamp units.
2283-
# This can be removed if/when pyarrow addresses it:
2284-
# https://github.com/apache/arrow/issues/34462
2285-
return np.dtype(f"datetime64[{self.pyarrow_dtype.unit}]")
2286-
if pa.types.is_duration(self.pyarrow_dtype):
2287-
# pa.duration(unit).to_pandas_dtype() returns ns units
2288-
# regardless of the pyarrow duration units
2289-
# This can be removed if/when pyarrow addresses it:
2290-
# https://github.com/apache/arrow/issues/34462
2291-
return np.dtype(f"timedelta64[{self.pyarrow_dtype.unit}]")
22922280
if pa.types.is_string(self.pyarrow_dtype) or pa.types.is_large_string(
22932281
self.pyarrow_dtype
22942282
):

pandas/tests/copy_view/test_astype.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
Series,
1212
Timestamp,
1313
date_range,
14+
to_datetime,
1415
)
1516
import pandas._testing as tm
1617
from pandas.tests.copy_view.util import get_array
@@ -236,3 +237,13 @@ def test_convert_dtypes(using_infer_string):
236237
df2.iloc[0, 0] = "x"
237238
df2.iloc[0, 1] = 10
238239
tm.assert_frame_equal(df, df_orig)
240+
241+
242+
def test_convert_dtypes_pyarrow_timezone():
243+
# GH 60237
244+
expected = Series(
245+
to_datetime(range(5), utc=True, unit="h"),
246+
dtype="timestamp[ns, tz=UTC][pyarrow]",
247+
)
248+
result = expected.convert_dtypes(dtype_backend="pyarrow")
249+
tm.assert_series_equal(result, expected)

0 commit comments

Comments
 (0)