Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

COMPAT: unicode_literals conflict with to_records #13172

Closed
starplanet opened this issue May 13, 2016 · 2 comments
Closed

COMPAT: unicode_literals conflict with to_records #13172

starplanet opened this issue May 13, 2016 · 2 comments
Labels
Compat pandas objects compatability with Numpy or Python functions Unicode Unicode strings
Milestone

Comments

@starplanet
Copy link
Contributor

starplanet commented May 13, 2016

Code Sample, a copy-pastable example if possible

from __future__ import unicode_literals
import pandas as pd
pd.DataFrame([{'id': '10', 'title': 'hello'}]).set_index('id').to_records()

the code above will report following error:

TypeError                                 Traceback (most recent call last)
<ipython-input-40-056b33fad34d> in <module>()
----> 1 pd.DataFrame([{'id': '10', 'title': 'hello'}]).set_index('id').to_records()

/usr/local/lib/python2.7/site-packages/pandas/core/frame.pyc in to_records(self, index, convert_datetime64)
   1068             names = lmap(str, self.columns)
   1069
-> 1070         dtype = np.dtype([(x, v.dtype) for x, v in zip(names, arrays)])
   1071         return np.rec.fromarrays(arrays, dtype=dtype, names=names)
   1072

TypeError: data type not understood

If I comment out from __future__ import unicode_literals, the code above will work fine.

rec.array([('10', 'hello')],
          dtype=[('id', 'O'), ('title', 'O')])

output of pd.show_versions()

INSTALLED VERSIONS

commit: None
python: 2.7.11.final.0
python-bits: 64
OS: Darwin
OS-release: 15.4.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: None
LANG: zh_CN.UTF-8

pandas: 0.18.1
nose: None
pip: 8.1.1
setuptools: 19.4
Cython: None
numpy: 1.11.0
scipy: None
statsmodels: None
xarray: None
IPython: 4.2.0
sphinx: 1.3.5
patsy: None
dateutil: 2.5.3
pytz: 2016.4
blosc: None
bottleneck: None
tables: None
numexpr: None
matplotlib: None
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: 4.4.1
html5lib: None
httplib2: None
apiclient: None
sqlalchemy: 1.0.12
pymysql: None
psycopg2: None
jinja2: 2.8
boto: None
pandas_datareader: None

@jreback
Copy link
Contributor

jreback commented May 13, 2016

https://github.com/pydata/pandas/blob/master/pandas/core/frame.py#L1068 should prob be

lmap(compat.u, self.columns)

want to do a PR?

@jreback jreback added Unicode Unicode strings 2/3 Compat Compat pandas objects compatability with Numpy or Python functions labels May 13, 2016
@jreback jreback added this to the 0.18.2 milestone May 13, 2016
@jreback jreback changed the title unicode_literals conflict with to_records COMPAT: unicode_literals conflict with to_records May 13, 2016
@starplanet
Copy link
Contributor Author

OK, I will have a try.

原始邮件
发件人:Jeff Rebacknotifications@github.com
收件人:pydata/pandaspandas@noreply.github.com
抄送:starplanetzhangjinjie@yimian.com.cn; Authorauthor@noreply.github.com
发送时间:2016年5月14日(周六) 00:56
主题:Re: [pydata/pandas] unicode_literals conflict with to_records(#13172)

https://github.com/pydata/pandas/blob/master/pandas/core/frame.py#L1068 should prob be
lmap(compat.u, self.columns)
want to do a PR?

You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Compat pandas objects compatability with Numpy or Python functions Unicode Unicode strings
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants