Skip to content

Commit 8f721e3

Browse files
committed
_new_PeriodIndex for unpickling
1 parent d04692f commit 8f721e3

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

pandas/indexes/base.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,8 @@ def _new_Index(cls, d):
8989
# required for backward compat, because PI can't be instantiated with
9090
# ordinals through __new__ GH #13277
9191
if issubclass(cls, ABCPeriodIndex):
92-
if d['data'].dtype == 'int64':
93-
values = d.pop('data')
94-
return cls._from_ordinals(values=values, **d)
92+
from pandas.tseries.period import _new_PeriodIndex
93+
return _new_PeriodIndex(cls, **d)
9594
return cls.__new__(cls, **d)
9695

9796

pandas/tseries/period.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,13 @@ def wrapper(self, other):
109109
return wrapper
110110

111111

112+
def _new_PeriodIndex(cls, **d):
113+
# GH13277 for unpickling
114+
if d['data'].dtype == 'int64':
115+
values = d.pop('data')
116+
return cls._from_ordinals(values=values, **d)
117+
118+
112119
class PeriodIndex(DatelikeOps, DatetimeIndexOpsMixin, Int64Index):
113120
"""
114121
Immutable ndarray holding ordinal values indicating regular periods in
@@ -204,9 +211,9 @@ def __new__(cls, data=None, ordinal=None, freq=None, start=None, end=None,
204211
msg = 'specified freq and dtype are different'
205212
raise IncompatibleFrequency(msg)
206213

207-
# coerce freq to freq object, otherwise it can be coorced elementwise
214+
# coerce freq to freq object, otherwise it can be coerced elementwise
208215
# which is slow
209-
if freq is not None:
216+
if freq:
210217
freq = Period._maybe_convert_freq(freq)
211218

212219
if data is None:

0 commit comments

Comments
 (0)