Skip to content

Commit 73e2829

Browse files
gfyoungjreback
authored andcommitted
BUG: Properly read Categorical msgpacks (pandas-dev#14918)
Patches bug in read_msgpack in which Series categoricals were accidentally being constructed with a non-categorical dtype, resulting in an error. Closes pandas-devgh-14901.
1 parent 07c83ee commit 73e2829

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

doc/source/whatsnew/v0.20.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ Bug Fixes
286286

287287

288288

289+
- Bug in ``pd.read_msgpack()`` in which ``Series`` categoricals were being improperly processed (:issue:`14901`)
289290

290291

291292

pandas/io/packers.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -593,17 +593,13 @@ def decode(obj):
593593
elif typ == u'series':
594594
dtype = dtype_for(obj[u'dtype'])
595595
pd_dtype = pandas_dtype(dtype)
596-
np_dtype = pandas_dtype(dtype).base
597596

598597
index = obj[u'index']
599598
result = globals()[obj[u'klass']](unconvert(obj[u'data'], dtype,
600599
obj[u'compress']),
601600
index=index,
602-
dtype=np_dtype,
601+
dtype=pd_dtype,
603602
name=obj[u'name'])
604-
tz = getattr(pd_dtype, 'tz', None)
605-
if tz:
606-
result = result.dt.tz_localize('UTC').dt.tz_convert(tz)
607603
return result
608604

609605
elif typ == u'block_manager':

pandas/io/tests/test_packers.py

+4
Original file line numberDiff line numberDiff line change
@@ -363,13 +363,17 @@ def setUp(self):
363363
'F': [Timestamp('20130102', tz='US/Eastern')] * 2 +
364364
[Timestamp('20130603', tz='CET')] * 3,
365365
'G': [Timestamp('20130102', tz='US/Eastern')] * 5,
366+
'H': Categorical([1, 2, 3, 4, 5]),
367+
'I': Categorical([1, 2, 3, 4, 5], ordered=True),
366368
}
367369

368370
self.d['float'] = Series(data['A'])
369371
self.d['int'] = Series(data['B'])
370372
self.d['mixed'] = Series(data['E'])
371373
self.d['dt_tz_mixed'] = Series(data['F'])
372374
self.d['dt_tz'] = Series(data['G'])
375+
self.d['cat_ordered'] = Series(data['H'])
376+
self.d['cat_unordered'] = Series(data['I'])
373377

374378
def test_basic(self):
375379

0 commit comments

Comments
 (0)