Skip to content

Commit a25fcba

Browse files
author
y-p
committed
BUG: PeriodIndex pickle roundtrip does not recreate freq GH2891
1 parent 793a5c9 commit a25fcba

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

pandas/tseries/period.py

+19
Original file line numberDiff line numberDiff line change
@@ -1115,6 +1115,25 @@ def append(self, other):
11151115
for x in to_concat]
11161116
return Index(com._concat_compat(to_concat), name=name)
11171117

1118+
def __reduce__(self):
1119+
"""Necessary for making this object picklable"""
1120+
object_state = list(np.ndarray.__reduce__(self))
1121+
subclass_state = (self.name, self.freq)
1122+
object_state[2] = (object_state[2], subclass_state)
1123+
return tuple(object_state)
1124+
1125+
def __setstate__(self, state):
1126+
"""Necessary for making this object picklable"""
1127+
if len(state) == 2:
1128+
nd_state, own_state = state
1129+
np.ndarray.__setstate__(self, nd_state)
1130+
self.name = own_state[0]
1131+
try: # backcompat
1132+
self.freq = own_state[1]
1133+
except:
1134+
pass
1135+
else: # pragma: no cover
1136+
np.ndarray.__setstate__(self, state)
11181137

11191138
def _get_ordinal_range(start, end, periods, freq):
11201139
if com._count_not_none(start, end, periods) < 2:

0 commit comments

Comments
 (0)