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

Series.to_json - invalid handling of quotes #29806

Closed
Enteee opened this issue Nov 22, 2019 · 4 comments
Closed

Series.to_json - invalid handling of quotes #29806

Enteee opened this issue Nov 22, 2019 · 4 comments

Comments

@Enteee
Copy link

Enteee commented Nov 22, 2019

Code Sample, a copy-pastable example if possible

import pandas as pd

pd.DataFrame([
  {'A':'a', 'B':'b'}
]).groupby(
  ['A','B']
).apply(
  lambda x: x.to_dict(orient='records')
).to_json()

produces an invalid JSON string:

'{"["a","b"]":[{"A":"a","B":"b"}]}'

Problem description

For the given transformation, the output of to_json of a pandas.core.series.Series is not a valid JSON object.

Would be nice if it was.

Expected Output

'{"[\'a\',\'b\']":[{"A":"a","B":"b"}]}'

Output of pd.show_versions()

INSTALLED VERSIONS

commit : None
python : 3.7.5.final.0
python-bits : 64
OS : Linux
OS-release : 4.19.84
machine : x86_64
processor :
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 0.25.2
numpy : 1.17.3
pytz : 2019.3
dateutil : 2.8.0
pip : None
setuptools : None
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.4.1
html5lib : 1.0.1
pymysql : None
psycopg2 : None
jinja2 : None
IPython : 7.8.0
pandas_datareader: None
bs4 : 4.8.1
bottleneck : 1.2.1
fastparquet : None
gcsfs : None
lxml.etree : 4.4.1
matplotlib : None
numexpr : 2.7.0
odfpy : None
openpyxl : 3.0.0
pandas_gbq : None
pyarrow : None
pytables : None
s3fs : None
scipy : 1.3.1
sqlalchemy : 1.3.10
tables : None
xarray : None
xlrd : 1.2.0
xlwt : 1.3.0
xlsxwriter : None

@ohad83
Copy link
Contributor

ohad83 commented Nov 23, 2019

Seems to work fine in master, output:
'{"(\'a\', \'b\')":[{"A":"a","B":"b"}]}'

@Enteee
Copy link
Author

Enteee commented Nov 26, 2019

Interesting, I can for sure reproduce this issue with 0.25.2.
So how do we go forward with this issue? Do you want me to close this?

@ohad83
Copy link
Contributor

ohad83 commented Nov 26, 2019

It does reproduce in 0.25.2 and also 0.25.3.
I believe this is a duplicate of #20500 and closed by #27618, so yeah, it can be closed.

@Enteee
Copy link
Author

Enteee commented Nov 27, 2019

k, thx.

@Enteee Enteee closed this as completed Nov 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants