Skip to content

Commit 65badbf

Browse files
authored
DEPR: Timestamp(dt64obj, tz=tz) (#49381)
1 parent aae800d commit 65badbf

File tree

3 files changed

+8
-21
lines changed

3 files changed

+8
-21
lines changed

doc/source/whatsnew/v2.0.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,7 @@ Removal of prior version deprecations/changes
295295
- 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`)
296296
- 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`)
297297
- Changed the behavior of :class:`Series` constructor, it will no longer infer a datetime64 or timedelta64 dtype from string entries (:issue:`41731`)
298+
- 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`)
298299
- Changed behavior of :class:`Index` constructor when passed a ``SparseArray`` or ``SparseDtype`` to retain that dtype instead of casting to ``numpy.ndarray`` (:issue:`43930`)
299300
- 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`)
300301
- 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`)

pandas/_libs/tslibs/timestamps.pyx

+2-11
Original file line numberDiff line numberDiff line change
@@ -1637,18 +1637,9 @@ class Timestamp(_Timestamp):
16371637

16381638
tzobj = maybe_get_tz(tz)
16391639
if tzobj is not None and is_datetime64_object(ts_input):
1640-
# GH#24559, GH#42288 In the future we will treat datetime64 as
1640+
# GH#24559, GH#42288 As of 2.0 we treat datetime64 as
16411641
# wall-time (consistent with DatetimeIndex)
1642-
warnings.warn(
1643-
"In a future version, when passing a np.datetime64 object and "
1644-
"a timezone to Timestamp, the datetime64 will be interpreted "
1645-
"as a wall time, not a UTC time. To interpret as a UTC time, "
1646-
"use `Timestamp(dt64).tz_localize('UTC').tz_convert(tz)`",
1647-
FutureWarning,
1648-
stacklevel=find_stack_level(),
1649-
)
1650-
# Once this deprecation is enforced, we can do
1651-
# return Timestamp(ts_input).tz_localize(tzobj)
1642+
return cls(ts_input).tz_localize(tzobj)
16521643

16531644
if nanosecond is None:
16541645
nanosecond = 0

pandas/tests/scalar/timestamp/test_constructors.py

+5-10
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,13 @@ def test_constructor_datetime64_with_tz(self):
5454
dt = np.datetime64("1970-01-01 05:00:00")
5555
tzstr = "UTC+05:00"
5656

57-
msg = "interpreted as a wall time"
58-
with tm.assert_produces_warning(FutureWarning, match=msg):
59-
ts = Timestamp(dt, tz=tzstr)
57+
# pre-2.0 this interpreted dt as a UTC time. in 2.0 this is treated
58+
# as a wall-time, consistent with DatetimeIndex behavior
59+
ts = Timestamp(dt, tz=tzstr)
6060

61-
# Check that we match the old behavior
62-
alt = Timestamp(dt).tz_localize("UTC").tz_convert(tzstr)
61+
alt = Timestamp(dt).tz_localize(tzstr)
6362
assert ts == alt
64-
65-
# Check that we *don't* match the future behavior
66-
assert ts.hour != 5
67-
expected_future = Timestamp(dt).tz_localize(tzstr)
68-
assert ts != expected_future
63+
assert ts.hour == 5
6964

7065
def test_constructor(self):
7166
base_str = "2014-07-01 09:00"

0 commit comments

Comments
 (0)