Skip to content

REGR: dont warn on unpickle Timestamp #42138

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 1 commit into from
Jun 21, 2021
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: 8 additions & 1 deletion pandas/_libs/tslibs/timestamps.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,13 @@ cdef inline object create_timestamp_from_ts(int64_t value,
return ts_base


def _unpickle_timestamp(value, freq, tz):
# GH#41949 dont warn on unpickle if we have a freq
ts = Timestamp(value, tz=tz)
ts._set_freq(freq)
return ts


# ----------------------------------------------------------------------

def integer_op_not_supported(obj):
Expand Down Expand Up @@ -725,7 +732,7 @@ cdef class _Timestamp(ABCTimestamp):

def __reduce__(self):
object_state = self.value, self._freq, self.tzinfo
return (Timestamp, object_state)
return (_unpickle_timestamp, object_state)

# -----------------------------------------------------------------
# Rendering Methods
Expand Down
12 changes: 12 additions & 0 deletions pandas/tests/scalar/timestamp/test_timestamp.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
timedelta,
)
import locale
import pickle
import unicodedata

from dateutil.tz import tzutc
Expand Down Expand Up @@ -440,6 +441,17 @@ def test_tz_conversion_freq(self, tz_naive_fixture):
t2 = Timestamp("2019-01-02 12:00", tz="UTC", freq="T")
assert t2.tz_convert(tz="UTC").freq == t2.freq

def test_pickle_freq_no_warning(self):
# GH#41949 we don't want a warning on unpickling
with tm.assert_produces_warning(FutureWarning, match="freq"):
ts = Timestamp("2019-01-01 10:00", freq="H")

out = pickle.dumps(ts)
with tm.assert_produces_warning(None):
res = pickle.loads(out)

assert res._freq == ts._freq


class TestTimestampNsOperations:
def test_nanosecond_string_parsing(self):
Expand Down