diff --git a/doc/source/whatsnew/v2.0.0.rst b/doc/source/whatsnew/v2.0.0.rst index 780318769f04e..d937f452b4023 100644 --- a/doc/source/whatsnew/v2.0.0.rst +++ b/doc/source/whatsnew/v2.0.0.rst @@ -281,6 +281,7 @@ Removal of prior version deprecations/changes - Changed behavior of :class:`DataFrame` constructor given floating-point ``data`` and an integer ``dtype``, when the data cannot be cast losslessly, the floating point dtype is retained, matching :class:`Series` behavior (:issue:`41170`) - Changed behavior of :class:`DataFrame` constructor when passed a ``dtype`` (other than int) that the data cannot be cast to; it now raises instead of silently ignoring the dtype (:issue:`41733`) - 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:`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`) - Changed behavior of :class:`Index` constructor when passed a ``SparseArray`` or ``SparseDtype`` to retain that dtype instead of casting to ``numpy.ndarray`` (:issue:`43930`) - Removed the deprecated ``base`` and ``loffset`` arguments from :meth:`pandas.DataFrame.resample`, :meth:`pandas.Series.resample` and :class:`pandas.Grouper`. Use ``offset`` or ``origin`` instead (:issue:`31809`) - 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`) 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"