Skip to content

Commit cd30262

Browse files
committed
BUG: Bug in pd.read_msgpack with inferring a DateTimeIndex frequencey
incorrectly (GH5947)
1 parent 14f4a78 commit cd30262

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

doc/source/release.rst

+2
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ Bug Fixes
107107
- ``pd.match`` not returning passed sentinel
108108
- ``Panel.to_frame()`` no longer fails when ``major_axis`` is a
109109
``MultiIndex`` (:issue:`5402`).
110+
- Bug in ``pd.read_msgpack`` with inferring a ``DateTimeIndex`` frequencey
111+
incorrectly (:issue:`5947`)
110112

111113
pandas 0.13.0
112114
-------------

pandas/io/packers.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -458,18 +458,19 @@ def decode(obj):
458458
return globals()[obj['klass']].from_tuples(data, names=obj['names'])
459459
elif typ == 'period_index':
460460
data = unconvert(obj['data'], np.int64, obj.get('compress'))
461-
return globals()[obj['klass']](data, name=obj['name'],
462-
freq=obj['freq'])
461+
d = dict(name=obj['name'], freq=obj['freq'])
462+
return globals()[obj['klass']](data, **d)
463463
elif typ == 'datetime_index':
464464
data = unconvert(obj['data'], np.int64, obj.get('compress'))
465-
result = globals()[obj['klass']](data, freq=obj['freq'],
466-
name=obj['name'])
465+
d = dict(name=obj['name'], freq=obj['freq'], verify_integrity=False)
466+
result = globals()[obj['klass']](data, **d)
467467
tz = obj['tz']
468468

469469
# reverse tz conversion
470470
if tz is not None:
471471
result = result.tz_localize('UTC').tz_convert(tz)
472472
return result
473+
473474
elif typ == 'series':
474475
dtype = dtype_for(obj['dtype'])
475476
index = obj['index']

pandas/io/tests/test_packers.py

+11
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,17 @@ def test_iterator(self):
372372
for i, packed in enumerate(read_msgpack(path, iterator=True)):
373373
check_arbitrary(packed, l[i])
374374

375+
def tests_datetimeindex_freq_issue(self):
376+
377+
# GH 5947
378+
# inferring freq on the datetimeindex
379+
df = DataFrame([1, 2, 3], index=date_range('1/1/2013', '1/3/2013'))
380+
result = self.encode_decode(df)
381+
assert_frame_equal(result, df)
382+
383+
df = DataFrame([1, 2], index=date_range('1/1/2013', '1/2/2013'))
384+
result = self.encode_decode(df)
385+
assert_frame_equal(result, df)
375386

376387
class TestSparse(TestPackers):
377388

0 commit comments

Comments
 (0)