Skip to content

BUG: Bug in pd.read_msgpack with inferring a DateTimeIndex frequency incorrectly (GH5947) #5948

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 1 commit into from
Jan 15, 2014
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 doc/source/release.rst
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ Bug Fixes
- ``pd.match`` not returning passed sentinel
- ``Panel.to_frame()`` no longer fails when ``major_axis`` is a
``MultiIndex`` (:issue:`5402`).
- Bug in ``pd.read_msgpack`` with inferring a ``DateTimeIndex`` frequencey
incorrectly (:issue:`5947`)

pandas 0.13.0
-------------
Expand Down
9 changes: 5 additions & 4 deletions pandas/io/packers.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,18 +458,19 @@ def decode(obj):
return globals()[obj['klass']].from_tuples(data, names=obj['names'])
elif typ == 'period_index':
data = unconvert(obj['data'], np.int64, obj.get('compress'))
return globals()[obj['klass']](data, name=obj['name'],
freq=obj['freq'])
d = dict(name=obj['name'], freq=obj['freq'])
return globals()[obj['klass']](data, **d)
elif typ == 'datetime_index':
data = unconvert(obj['data'], np.int64, obj.get('compress'))
result = globals()[obj['klass']](data, freq=obj['freq'],
name=obj['name'])
d = dict(name=obj['name'], freq=obj['freq'], verify_integrity=False)
result = globals()[obj['klass']](data, **d)
tz = obj['tz']

# reverse tz conversion
if tz is not None:
result = result.tz_localize('UTC').tz_convert(tz)
return result

elif typ == 'series':
dtype = dtype_for(obj['dtype'])
index = obj['index']
Expand Down
11 changes: 11 additions & 0 deletions pandas/io/tests/test_packers.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,17 @@ def test_iterator(self):
for i, packed in enumerate(read_msgpack(path, iterator=True)):
check_arbitrary(packed, l[i])

def tests_datetimeindex_freq_issue(self):

# GH 5947
# inferring freq on the datetimeindex
df = DataFrame([1, 2, 3], index=date_range('1/1/2013', '1/3/2013'))
result = self.encode_decode(df)
assert_frame_equal(result, df)

df = DataFrame([1, 2], index=date_range('1/1/2013', '1/2/2013'))
result = self.encode_decode(df)
assert_frame_equal(result, df)

class TestSparse(TestPackers):

Expand Down