Skip to content

Commit 4bb45b1

Browse files
committed
Merge pull request #10527 from kawochen/BUG-FIX-9618
BUG: GH9618 in read_msgpack where DataFrame has duplicate column names
2 parents 061c506 + ed775bc commit 4bb45b1

11 files changed

+295
-174
lines changed

doc/source/whatsnew/v0.17.0.txt

+3-1
Original file line numberDiff line numberDiff line change
@@ -385,4 +385,6 @@ Bug Fixes
385385

386386
- Bug in operator equal on Index not being consistent with Series (:issue:`9947`)
387387

388-
- Reading "famafrench" data via ``DataReader`` results in HTTP 404 error because of the website url is changed (:issue:`10591`).
388+
- Reading "famafrench" data via ``DataReader`` results in HTTP 404 error because of the website url is changed (:issue:`10591`).
389+
390+
- Bug in `read_msgpack` where DataFrame to decode has duplicate column names (:issue:`9618`)

pandas/io/packers.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,7 @@ def encode(obj):
357357
'klass': obj.__class__.__name__,
358358
'axes': data.axes,
359359
'blocks': [{'items': data.items.take(b.mgr_locs),
360+
'locs': b.mgr_locs.as_array,
360361
'values': convert(b.values),
361362
'shape': b.values.shape,
362363
'dtype': b.dtype.num,
@@ -485,9 +486,15 @@ def decode(obj):
485486
def create_block(b):
486487
values = unconvert(b['values'], dtype_for(b['dtype']),
487488
b['compress']).reshape(b['shape'])
489+
490+
# locs handles duplicate column names, and should be used instead of items; see GH 9618
491+
if 'locs' in b:
492+
placement = b['locs']
493+
else:
494+
placement = axes[0].get_indexer(b['items'])
488495
return make_block(values=values,
489496
klass=getattr(internals, b['klass']),
490-
placement=axes[0].get_indexer(b['items']))
497+
placement=placement)
491498

492499
blocks = [create_block(b) for b in obj['blocks']]
493500
return globals()[obj['klass']](BlockManager(blocks, axes))
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

pandas/io/tests/generate_legacy_pickles.py

-167
This file was deleted.

0 commit comments

Comments
 (0)