Skip to content

ENH: Timestamp pickle support non-nano tzaware #47340

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
Jun 14, 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
9 changes: 1 addition & 8 deletions pandas/_libs/tslibs/timestamps.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,7 @@ cdef inline _Timestamp create_timestamp_from_ts(

def _unpickle_timestamp(value, freq, tz, reso=NPY_FR_ns):
# GH#41949 dont warn on unpickle if we have a freq
if reso == NPY_FR_ns:
ts = Timestamp(value, tz=tz)
else:
if tz is not None:
raise NotImplementedError
abbrev = npy_unit_to_abbrev(reso)
dt64 = np.datetime64(value, abbrev)
ts = Timestamp._from_dt64(dt64)
ts = Timestamp._from_value_and_reso(value, reso, tz)
ts._set_freq(freq)
return ts

Expand Down
6 changes: 5 additions & 1 deletion pandas/tests/scalar/timestamp/test_timestamp.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from pandas._libs.tslibs.timezones import (
dateutil_gettz as gettz,
get_timezone,
maybe_get_tz,
tz_compare,
)
from pandas.errors import OutOfBoundsDatetime
Expand Down Expand Up @@ -836,7 +837,10 @@ def test_cmp_cross_reso_reversed_dt64(self):

assert other.asm8 < ts

def test_pickle(self, ts):
def test_pickle(self, ts, tz_aware_fixture):
tz = tz_aware_fixture
tz = maybe_get_tz(tz)
ts = Timestamp._from_value_and_reso(ts.value, ts._reso, tz)
rt = tm.round_trip_pickle(ts)
assert rt._reso == ts._reso
assert rt == ts
Expand Down