Skip to content

Commit 91d85cb

Browse files
committed
msgpack supports CategoricalIndex
1 parent b94186d commit 91d85cb

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

pandas/io/packers.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
from pandas import (Timestamp, Period, Series, DataFrame, # noqa
5555
Index, MultiIndex, Float64Index, Int64Index,
5656
Panel, RangeIndex, PeriodIndex, DatetimeIndex, NaT,
57-
Categorical)
57+
Categorical, CategoricalIndex)
5858
from pandas.tslib import NaTType
5959
from pandas.sparse.api import SparseSeries, SparseDataFrame
6060
from pandas.sparse.array import BlockIndex, IntIndex

pandas/tests/msgpack/test_unpack.py

+12-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from pandas.msgpack import Unpacker, packb, OutOfData, ExtType
44
import pandas.util.testing as tm
55
import pytest
6-
6+
from pandas import DataFrame
77

88
class TestUnpack(tm.TestCase):
99

@@ -62,3 +62,14 @@ def _hook(self, code, data):
6262
assert unpacker.unpack() == {'a': 123}
6363
unpacker.feed(packb({'a': ExtType(2, b'321')}, encoding='utf-8'))
6464
assert unpacker.unpack() == {'a': ExtType(2, b'321')}
65+
66+
def test_unpack_categorical_index(self):
67+
'''dataframe with CategoricalIndex can be read and written'''
68+
pdf = pd.DataFrame(dict(A=[1,1,1,2,2,2], B = [1,2,3,4,5,6]))
69+
pdf['A'] = pdf['A'].astype('category')
70+
pdf.set_index('A', inplace = True)
71+
f = BytesIO()
72+
pdf.to_msgpack(f)
73+
f.seek(0)
74+
pdf2 = pd.read_msgpack(f)
75+
tm.assert_frame_equal(pdf, pdf2)

0 commit comments

Comments
 (0)