Skip to content

BUG: Fixed msgpack roundtrip with PeriodIndex #24335

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 2 commits into from
Dec 18, 2018
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
2 changes: 2 additions & 0 deletions pandas/core/indexes/period.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,8 @@ def _simple_new(cls, values, name=None, freq=None, **kwargs):
values = np.asarray(values)
if is_float_dtype(values):
raise TypeError("PeriodIndex._simple_new does not accept floats.")
if freq:
freq = Period._maybe_convert_freq(freq)
values = PeriodArray(values, freq=freq)

if not isinstance(values, PeriodArray):
Expand Down
2 changes: 1 addition & 1 deletion pandas/io/packers.py
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ def decode(obj):
elif typ == u'datetime_index':
data = unconvert(obj[u'data'], np.int64, obj.get(u'compress'))
d = dict(name=obj[u'name'], freq=obj[u'freq'])
result = DatetimeIndex._simple_new(data, **d)
result = DatetimeIndex(data, **d)
tz = obj[u'tz']

# reverse tz conversion
Expand Down
6 changes: 6 additions & 0 deletions pandas/tests/io/test_packers.py
Original file line number Diff line number Diff line change
Expand Up @@ -940,3 +940,9 @@ def test_msgpacks_legacy(self, current_packers_data, all_packers_data,
except ImportError:
# blosc not installed
pass

def test_msgpack_period_freq(self):
# https://github.com/pandas-dev/pandas/issues/24135
s = Series(np.random.rand(5), index=date_range('20130101', periods=5))
r = read_msgpack(s.to_msgpack())
repr(r)