Skip to content

msgpack supports CategoricalIndex #15493

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

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 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: 1 addition & 1 deletion pandas/io/packers.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
from pandas import (Timestamp, Period, Series, DataFrame, # noqa
Index, MultiIndex, Float64Index, Int64Index,
Panel, RangeIndex, PeriodIndex, DatetimeIndex, NaT,
Categorical)
Categorical, CategoricalIndex)
from pandas.tslib import NaTType
from pandas.sparse.api import SparseSeries, SparseDataFrame
from pandas.sparse.array import BlockIndex, IntIndex
Expand Down
12 changes: 12 additions & 0 deletions pandas/tests/msgpack/test_unpack.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from pandas.msgpack import Unpacker, packb, OutOfData, ExtType
import pandas.util.testing as tm
import pytest
from pandas import DataFrame, read_msgpack


class TestUnpack(tm.TestCase):
Expand Down Expand Up @@ -62,3 +63,14 @@ def _hook(self, code, data):
assert unpacker.unpack() == {'a': 123}
unpacker.feed(packb({'a': ExtType(2, b'321')}, encoding='utf-8'))
assert unpacker.unpack() == {'a': ExtType(2, b'321')}

def test_unpack_categorical_index(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the tests are all in pandas/tests/io/test_packers.py (this section is for the c-code that implements msgpack itself).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just follow examples there for style

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I tried to change the it accordingly. Do you get a notification if I push new commits? Or should I comment?

'''dataframe with CategoricalIndex can be read and written'''
pdf = DataFrame(dict(A=[1, 1, 1, 2, 2, 2], B=[1, 2, 3, 4, 5, 6]))
pdf['A'] = pdf['A'].astype('category')
pdf.set_index('A', inplace=True)
f = BytesIO()
pdf.to_msgpack(f)
f.seek(0)
pdf2 = read_msgpack(f)
tm.assert_frame_equal(pdf, pdf2)