Skip to content

Commit f0dd94b

Browse files
jbrockmendelneinkeinkaffee
authored andcommitted
REGR: dont warn on unpickle Timestamp (pandas-dev#42138)
1 parent 859c118 commit f0dd94b

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

pandas/_libs/tslibs/timestamps.pyx

+8-1
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,13 @@ cdef inline object create_timestamp_from_ts(int64_t value,
129129
return ts_base
130130

131131

132+
def _unpickle_timestamp(value, freq, tz):
133+
# GH#41949 dont warn on unpickle if we have a freq
134+
ts = Timestamp(value, tz=tz)
135+
ts._set_freq(freq)
136+
return ts
137+
138+
132139
# ----------------------------------------------------------------------
133140

134141
def integer_op_not_supported(obj):
@@ -725,7 +732,7 @@ cdef class _Timestamp(ABCTimestamp):
725732

726733
def __reduce__(self):
727734
object_state = self.value, self._freq, self.tzinfo
728-
return (Timestamp, object_state)
735+
return (_unpickle_timestamp, object_state)
729736

730737
# -----------------------------------------------------------------
731738
# Rendering Methods

pandas/tests/scalar/timestamp/test_timestamp.py

+12
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
timedelta,
77
)
88
import locale
9+
import pickle
910
import unicodedata
1011

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

444+
def test_pickle_freq_no_warning(self):
445+
# GH#41949 we don't want a warning on unpickling
446+
with tm.assert_produces_warning(FutureWarning, match="freq"):
447+
ts = Timestamp("2019-01-01 10:00", freq="H")
448+
449+
out = pickle.dumps(ts)
450+
with tm.assert_produces_warning(None):
451+
res = pickle.loads(out)
452+
453+
assert res._freq == ts._freq
454+
443455

444456
class TestTimestampNsOperations:
445457
def test_nanosecond_string_parsing(self):

0 commit comments

Comments
 (0)