From a4a42d9a215ea73753374c24de9e5ee65db69571 Mon Sep 17 00:00:00 2001 From: Brock Date: Fri, 28 Oct 2022 16:10:14 -0700 Subject: [PATCH] DEPR: Timestamp(dt64obj, tz=tz) --- doc/source/whatsnew/v2.0.0.rst | 1 + pandas/_libs/tslibs/timestamps.pyx | 13 ++----------- .../tests/scalar/timestamp/test_constructors.py | 15 +++++---------- 3 files changed, 8 insertions(+), 21 deletions(-) diff --git a/doc/source/whatsnew/v2.0.0.rst b/doc/source/whatsnew/v2.0.0.rst index 0004bc92b349e..6739762b484c6 100644 --- a/doc/source/whatsnew/v2.0.0.rst +++ b/doc/source/whatsnew/v2.0.0.rst @@ -271,6 +271,7 @@ Removal of prior version deprecations/changes - Changed the behavior of :class:`Series` constructor, it will no longer infer a datetime64 or timedelta64 dtype from string entries (:issue:`41731`) - Changed behavior of :class:`Index` constructor when passed a ``SparseArray`` or ``SparseDtype`` to retain that dtype instead of casting to ``numpy.ndarray`` (:issue:`43930`) - Changed behavior of :meth:`DataFrame.any` and :meth:`DataFrame.all` with ``bool_only=True``; object-dtype columns with all-bool values will no longer be included, manually cast to ``bool`` dtype first (:issue:`46188`) +- Changed behavior of :class:`Timestamp` constructor with a ``np.datetime64`` object and a ``tz`` passed to interpret the input as a wall-time as opposed to a UTC time (:issue:`42288`) - .. --------------------------------------------------------------------------- diff --git a/pandas/_libs/tslibs/timestamps.pyx b/pandas/_libs/tslibs/timestamps.pyx index 3c3bb8496aa6e..bfc6f872675d6 100644 --- a/pandas/_libs/tslibs/timestamps.pyx +++ b/pandas/_libs/tslibs/timestamps.pyx @@ -1639,18 +1639,9 @@ class Timestamp(_Timestamp): tzobj = maybe_get_tz(tz) if tzobj is not None and is_datetime64_object(ts_input): - # GH#24559, GH#42288 In the future we will treat datetime64 as + # GH#24559, GH#42288 As of 2.0 we treat datetime64 as # wall-time (consistent with DatetimeIndex) - warnings.warn( - "In a future version, when passing a np.datetime64 object and " - "a timezone to Timestamp, the datetime64 will be interpreted " - "as a wall time, not a UTC time. To interpret as a UTC time, " - "use `Timestamp(dt64).tz_localize('UTC').tz_convert(tz)`", - FutureWarning, - stacklevel=find_stack_level(), - ) - # Once this deprecation is enforced, we can do - # return Timestamp(ts_input).tz_localize(tzobj) + return cls(ts_input).tz_localize(tzobj) if nanosecond is None: nanosecond = 0 diff --git a/pandas/tests/scalar/timestamp/test_constructors.py b/pandas/tests/scalar/timestamp/test_constructors.py index 341e850a7464e..ba24804ce4634 100644 --- a/pandas/tests/scalar/timestamp/test_constructors.py +++ b/pandas/tests/scalar/timestamp/test_constructors.py @@ -54,18 +54,13 @@ def test_constructor_datetime64_with_tz(self): dt = np.datetime64("1970-01-01 05:00:00") tzstr = "UTC+05:00" - msg = "interpreted as a wall time" - with tm.assert_produces_warning(FutureWarning, match=msg): - ts = Timestamp(dt, tz=tzstr) + # pre-2.0 this interpreted dt as a UTC time. in 2.0 this is treated + # as a wall-time, consistent with DatetimeIndex behavior + ts = Timestamp(dt, tz=tzstr) - # Check that we match the old behavior - alt = Timestamp(dt).tz_localize("UTC").tz_convert(tzstr) + alt = Timestamp(dt).tz_localize(tzstr) assert ts == alt - - # Check that we *don't* match the future behavior - assert ts.hour != 5 - expected_future = Timestamp(dt).tz_localize(tzstr) - assert ts != expected_future + assert ts.hour == 5 def test_constructor(self): base_str = "2014-07-01 09:00"