From 441d6d3c9e4e37e4e75161ba8660f9142275d43f Mon Sep 17 00:00:00 2001 From: road-1 <165108013+road-1@users.noreply.github.com> Date: Tue, 19 Nov 2024 11:56:52 -0500 Subject: [PATCH 1/3] Update dtypes.py removed if statements --- pandas/core/dtypes/dtypes.py | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/pandas/core/dtypes/dtypes.py b/pandas/core/dtypes/dtypes.py index 96b0aa16940a6..67c09884d03dd 100644 --- a/pandas/core/dtypes/dtypes.py +++ b/pandas/core/dtypes/dtypes.py @@ -2277,18 +2277,6 @@ def name(self) -> str: # type: ignore[override] @cache_readonly def numpy_dtype(self) -> np.dtype: """Return an instance of the related numpy dtype""" - if pa.types.is_timestamp(self.pyarrow_dtype): - # pa.timestamp(unit).to_pandas_dtype() returns ns units - # regardless of the pyarrow timestamp units. - # This can be removed if/when pyarrow addresses it: - # https://github.com/apache/arrow/issues/34462 - return np.dtype(f"datetime64[{self.pyarrow_dtype.unit}]") - if pa.types.is_duration(self.pyarrow_dtype): - # pa.duration(unit).to_pandas_dtype() returns ns units - # regardless of the pyarrow duration units - # This can be removed if/when pyarrow addresses it: - # https://github.com/apache/arrow/issues/34462 - return np.dtype(f"timedelta64[{self.pyarrow_dtype.unit}]") if pa.types.is_string(self.pyarrow_dtype) or pa.types.is_large_string( self.pyarrow_dtype ): From 16c71fddc0a94fd13e3f187dceddd8751a164d21 Mon Sep 17 00:00:00 2001 From: road-1 <165108013+road-1@users.noreply.github.com> Date: Tue, 19 Nov 2024 11:57:46 -0500 Subject: [PATCH 2/3] Update test_arrow.py added test case --- pandas/tests/extension/test_arrow.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pandas/tests/extension/test_arrow.py b/pandas/tests/extension/test_arrow.py index f0ff11e5fa3f7..90d50dc086bc7 100644 --- a/pandas/tests/extension/test_arrow.py +++ b/pandas/tests/extension/test_arrow.py @@ -3507,3 +3507,13 @@ def test_map_numeric_na_action(): result = ser.map(lambda x: 42, na_action="ignore") expected = pd.Series([42.0, 42.0, np.nan], dtype="float64") tm.assert_series_equal(result, expected) + +def test_convert_dtypes_timezone_series(): + # GH#60237 + ser = pd.Series(pd.date_range(start='2020-01-01', + periods=5, freq='h', + tz='UTC'), + dtype="timestamp[ns, tz=UTC][pyarrow]") + expected = ser + result = ser.convert_dtypes(dtype_backend="pyarrow") + tm.assert_series_equal(result, expected) From a6fcbd24babf54cdc34887ce4ada16ec3e686bfe Mon Sep 17 00:00:00 2001 From: road-1 <165108013+road-1@users.noreply.github.com> Date: Tue, 19 Nov 2024 11:58:34 -0500 Subject: [PATCH 3/3] Update v3.0.0.rst --- doc/source/whatsnew/v3.0.0.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/source/whatsnew/v3.0.0.rst b/doc/source/whatsnew/v3.0.0.rst index de69166b8c196..03e64319ff791 100644 --- a/doc/source/whatsnew/v3.0.0.rst +++ b/doc/source/whatsnew/v3.0.0.rst @@ -649,6 +649,7 @@ Conversion - Bug in :meth:`DataFrame.update` bool dtype being converted to object (:issue:`55509`) - Bug in :meth:`Series.astype` might modify read-only array inplace when casting to a string dtype (:issue:`57212`) - Bug in :meth:`Series.reindex` not maintaining ``float32`` type when a ``reindex`` introduces a missing value (:issue:`45857`) +- Bug in :meth: 'Series.convert_dtype' strips the timezone on an already Timezone aware pyarrow timestamp dtype (:issue:'60237') Strings ^^^^^^^