Skip to content

Commit 67a8fc6

Browse files
committed
COMPAT: Category pickle compat
1 parent 1d226f7 commit 67a8fc6

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

pandas/core/categorical.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,8 @@ class Categorical(PandasObject):
187187

188188
# For comparisons, so that numpy uses our implementation if the compare ops, which raise
189189
__array_priority__ = 1000
190+
ordered = False
191+
name = None
190192

191193
def __init__(self, values, categories=None, ordered=None, name=None, fastpath=False,
192194
levels=None):
@@ -718,6 +720,19 @@ def __array__(self, dtype=None):
718720
return np.asarray(ret, dtype)
719721
return ret
720722

723+
def __setstate__(self, state):
724+
"""Necessary for making this object picklable"""
725+
if not isinstance(state, dict):
726+
raise Exception('invalid pickle state')
727+
728+
if 'labels' in state:
729+
state['_codes'] = state.pop('labels')
730+
if '_levels' in state:
731+
state['categories'] = state.pop('_levels')
732+
733+
for k, v in compat.iteritems(state):
734+
setattr(self,k,v)
735+
721736
@property
722737
def T(self):
723738
return self

0 commit comments

Comments
 (0)