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

mixed data type to_json(orient='index') repeats only the first index value #10289

Closed
sborgeson opened this issue Jun 5, 2015 · 3 comments · Fixed by #10306
Closed

mixed data type to_json(orient='index') repeats only the first index value #10289

sborgeson opened this issue Jun 5, 2015 · 3 comments · Fixed by #10306
Labels
Bug IO JSON read_json, to_json, json_normalize
Milestone

Comments

@sborgeson
Copy link

from pandas import DataFrame
df = DataFrame({
    'one' : pandas.Series(['foo','bar','bee'],index=['a','b','c']),
    'two' : pandas.Series([1,2,3],index=['a','b','c'])   } )
df.to_json(orient='index')

Observe that the first index value 'a' is used for all the record returned, rather than for just the first one. I've reproduced this issue on a linux machine with the config below, but it was first observed on OSX and can reproduce it on Windows, all with pandas 0.16.1.

This issue was not present in pandas version 0.14.x

pandas.show_versions()

INSTALLED VERSIONS

commit: None
python: 2.6.8.final.0
python-bits: 64
OS: Linux
OS-release: 2.6.18-274.el5
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8

pandas: 0.16.1
nose: None
Cython: None
numpy: 1.9.2
scipy: None
statsmodels: None
IPython: None
sphinx: None
patsy: None
dateutil: 2.4.2
pytz: 2015.4
bottleneck: None
tables: 3.2.0
numexpr: 2.4.3
matplotlib: None
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: None
httplib2: None
apiclient: None
sqlalchemy: None
pymysql: None
psycopg2: None

@jreback jreback added Bug IO JSON read_json, to_json, json_normalize labels Jun 5, 2015
@jreback jreback added this to the Next Major Release milestone Jun 5, 2015
@jreback
Copy link
Contributor

jreback commented Jun 5, 2015

hmm, does look odd. pull-requests welcome!
cc @Komnomnomnom

@sborgeson
Copy link
Author

For what it's worth, it appears the bug is in the native implementation of dumps. For my purposes, it was acceptable to convert all the dtypes to strings prior to serialization, but this will tend to change the data types on the receiving end as well:

df.astype(str).to_json(orient='index')

@makmanalp
Copy link
Contributor

Just hit this today. Thank you! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug IO JSON read_json, to_json, json_normalize
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants