diff --git a/pandas/tests/series/methods/test_astype.py b/pandas/tests/series/methods/test_astype.py index 7fbdc455a8dcf..732d375d136d0 100644 --- a/pandas/tests/series/methods/test_astype.py +++ b/pandas/tests/series/methods/test_astype.py @@ -16,6 +16,7 @@ NA, Categorical, CategoricalDtype, + DatetimeTZDtype, Index, Interval, NaT, @@ -363,6 +364,38 @@ def test_astype_nan_to_bool(self): expected = Series(True, dtype="bool") tm.assert_series_equal(result, expected) + @pytest.mark.parametrize( + "dtype", + tm.ALL_INT_EA_DTYPES + tm.FLOAT_EA_DTYPES, + ) + def test_astype_ea_to_datetimetzdtype(self, dtype): + # GH37553 + result = Series([4, 0, 9], dtype=dtype).astype(DatetimeTZDtype(tz="US/Pacific")) + expected = Series( + { + 0: Timestamp("1969-12-31 16:00:00.000000004-08:00", tz="US/Pacific"), + 1: Timestamp("1969-12-31 16:00:00.000000000-08:00", tz="US/Pacific"), + 2: Timestamp("1969-12-31 16:00:00.000000009-08:00", tz="US/Pacific"), + } + ) + + if dtype in tm.FLOAT_EA_DTYPES: + expected = Series( + { + 0: Timestamp( + "1970-01-01 00:00:00.000000004-08:00", tz="US/Pacific" + ), + 1: Timestamp( + "1970-01-01 00:00:00.000000000-08:00", tz="US/Pacific" + ), + 2: Timestamp( + "1970-01-01 00:00:00.000000009-08:00", tz="US/Pacific" + ), + } + ) + + tm.assert_series_equal(result, expected) + class TestAstypeString: @pytest.mark.parametrize(