Skip to content

Commit 75ff54d

Browse files
committed
_new_PeriodIndex for unpickling
1 parent 240172f commit 75ff54d

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
@@ -91,9 +91,8 @@ def _new_Index(cls, d):
9191
# required for backward compat, because PI can't be instantiated with
9292
# ordinals through __new__ GH #13277
9393
if issubclass(cls, ABCPeriodIndex):
94-
if d['data'].dtype == 'int64':
95-
values = d.pop('data')
96-
return cls._from_ordinals(values=values, **d)
94+
from pandas.tseries.period import _new_PeriodIndex
95+
return _new_PeriodIndex(cls, **d)
9796
return cls.__new__(cls, **d)
9897

9998

pandas/tseries/period.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,13 @@ def wrapper(self, other):
113113
return wrapper
114114

115115

116+
def _new_PeriodIndex(cls, **d):
117+
# GH13277 for unpickling
118+
if d['data'].dtype == 'int64':
119+
values = d.pop('data')
120+
return cls._from_ordinals(values=values, **d)
121+
122+
116123
class PeriodIndex(DatelikeOps, DatetimeIndexOpsMixin, Int64Index):
117124
"""
118125
Immutable ndarray holding ordinal values indicating regular periods in
@@ -208,9 +215,9 @@ def __new__(cls, data=None, ordinal=None, freq=None, start=None, end=None,
208215
msg = 'specified freq and dtype are different'
209216
raise IncompatibleFrequency(msg)
210217

211-
# coerce freq to freq object, otherwise it can be coorced elementwise
218+
# coerce freq to freq object, otherwise it can be coerced elementwise
212219
# which is slow
213-
if freq is not None:
220+
if freq:
214221
freq = Period._maybe_convert_freq(freq)
215222

216223
if data is None:

0 commit comments

Comments
 (0)