Skip to content

Commit d80275d

Browse files
abastjreback
authored andcommitted
BUG: msgpack supports CategoricalIndex
closes #15487 Author: Arco Bast <[email protected]> Closes #15493 from abast/CategoricalIndex_msgpack and squashes the following commits: c1c68e4 [Arco Bast] corrections 3c1f2e7 [Arco Bast] whatsnew 215c2aa [Arco Bast] improve tests cd9354f [Arco Bast] improve tests 7895c16 [Arco Bast] flake8 f3f492a [Arco Bast] fix test 91d85cb [Arco Bast] msgpack supports CategoricalIndex
1 parent 5955804 commit d80275d

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

doc/source/whatsnew/v0.20.0.txt

+2
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,7 @@ Bug Fixes
615615
- Bug in ``DataFrame.fillna()`` where the argument ``downcast`` was ignored when fillna value was of type ``dict`` (:issue:`15277`)
616616
- Bug in ``.reset_index()`` when an all ``NaN`` level of a ``MultiIndex`` would fail (:issue:`6322`)
617617

618+
- Bug in ``pd.read_msgpack`` when deserializing a ``CategoricalIndex`` (:issue:`15487`)
618619

619620

620621
- Bug in ``pd.read_csv()`` with ``float_precision='round_trip'`` which caused a segfault when a text entry is parsed (:issue:`15140`)
@@ -630,3 +631,4 @@ Bug Fixes
630631
- Bug in ``Series.replace`` and ``DataFrame.replace`` which failed on empty replacement dicts (:issue:`15289`)
631632
- Bug in ``pd.melt()`` where passing a tuple value for ``value_vars`` caused a ``TypeError`` (:issue:`15348`)
632633
- Bug in ``.eval()`` which caused multiline evals to fail with local variables not on the first line (:issue:`15342`)
634+
- Bug in ``pd.read_msgpack`` which did not allow to load dataframe with an index of type ``CategoricalIndex`` (:issue:`15487`)

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/io/test_packers.py

+8
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@ def setUp(self):
311311
'period': Index(period_range('2012-1-1', freq='M', periods=3)),
312312
'date2': Index(date_range('2013-01-1', periods=10)),
313313
'bdate': Index(bdate_range('2013-01-02', periods=10)),
314+
'cat': tm.makeCategoricalIndex(100)
314315
}
315316

316317
self.mi = {
@@ -349,6 +350,13 @@ def test_unicode(self):
349350
i_rec = self.encode_decode(i)
350351
self.assert_index_equal(i, i_rec)
351352

353+
def categorical_index(self):
354+
# GH15487
355+
df = DataFrame(np.random.randn(10, 2))
356+
df = df.astype({0: 'category'}).set_index(0)
357+
result = self.encode_decode(df)
358+
tm.assert_frame_equal(result, df)
359+
352360

353361
class TestSeries(TestPackers):
354362

0 commit comments

Comments
 (0)