Skip to content

DEPR: Timestamp(dt64obj, tz=tz) #49381

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/whatsnew/v2.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
Expand Down
13 changes: 2 additions & 11 deletions pandas/_libs/tslibs/timestamps.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 5 additions & 10 deletions pandas/tests/scalar/timestamp/test_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down