Closed
Description
Code Sample, a copy-pastable example if possible
Step 1. Run the code with Python 2 and Python 3
from sys import version
from pandas import DataFrame
print(version)
vers = version[0]
file_name = 'foobar'
data = {'a': [1], 'b': [2]}
dtf = DataFrame(data=data)
dtf.to_msgpack(file_name + '_py{}.msg'.format(vers))
Step 2. Run the code with Python 2 and Python 3
from sys import version
from pandas import read_msgpack
print(version)
vers = version[0]
file_name = 'foobar'
dtf = read_msgpack(file_name + '_py3.msg'.format(vers))
print(dtf.columns)
print(dtf.a)
dtf = read_msgpack(file_name + '_py2.msg'.format(vers))
# dtf.columns = [i.decode("utf-8") for i in dtf.columns]
print(dtf.columns)
print(dtf.a)
Expected Output
Same result with Python 2 and Python 3
Python 2 output:
2.7.10 (default, Oct 23 2015, 19:19:21)
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)]
Index([u'a', u'b'], dtype='object')
0 1
Name: a, dtype: int64
Index([u'a', u'b'], dtype='object')
0 1
Name: a, dtype: int64
Python 3 output, the exception it is not expected:
3.5.1 (v3.5.1:37a07cee5969, Dec 5 2015, 21:12:44)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)]
Index(['a', 'b'], dtype='object')
0 1
Name: a, dtype: int64
Index([b'a', b'b'], dtype='object')
Traceback (most recent call last):
File "/Users/VV/GitHub/doptimization/bug_msgpack_reader.py", line 16, in <module>
print(dtf.a)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pandas/core/generic.py", line 2669, in __getattr__
return object.__getattribute__(self, name)
AttributeError: 'DataFrame' object has no attribute 'a'
output of pd.show_versions()
INSTALLED VERSIONS
------------------
commit: None
python: 3.5.1.final.0
python-bits: 64
OS: Darwin
OS-release: 15.5.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: None
LANG: None
pandas: 0.18.0
nose: None
pip: 8.1.2
setuptools: 20.6.7
Cython: None
numpy: 1.11.0
scipy: 0.16.1
statsmodels: None
xarray: None
INSTALLED VERSIONS
------------------
commit: None
python: 3.5.1.final.0
python-bits: 64
OS: Darwin
OS-release: 15.5.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: None
LANG: None
pandas: 0.18.0
nose: None
pip: 8.1.2
setuptools: 20.6.7
Cython: None
numpy: 1.11.0
scipy: 0.16.1
statsmodels: None
xarray: None
IPython: 4.0.1
sphinx: None
patsy: None
dateutil: 2.5.2
pytz: 2016.3
blosc: None
bottleneck: None
tables: None
numexpr: None
matplotlib: 1.5.0
openpyxl: 2.3.5
xlrd: 1.0.0
xlwt: 1.0.0
xlsxwriter: None
lxml: None
bs4: 4.4.1
html5lib: None
httplib2: 0.9.2
apiclient: 1.5.0
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.8
boto: None
None
3.5.1 (v3.5.1:37a07cee5969, Dec 5 2015, 21:12:44)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)]
Index(['a', 'b'], dtype='object')
0 1
Name: a, dtype: int64
Index([b'a', b'b'], dtype='object')
IPython: 4.0.1
sphinx: None
patsy: None
dateutil: 2.5.2
pytz: 2016.3
blosc: None
bottleneck: None
tables: None
numexpr: None
matplotlib: 1.5.0
openpyxl: 2.3.5
xlrd: 1.0.0
xlwt: 1.0.0
xlsxwriter: None
lxml: None
bs4: 4.4.1
html5lib: None
httplib2: 0.9.2
apiclient: 1.5.0
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.8
boto: None
None