Skip to content

DOC: fix EX03 Errors for pandas.read_json #56865

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

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion ci/code_checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
pandas.errors.SettingWithCopyWarning \
pandas.errors.SpecificationError \
pandas.errors.UndefinedVariableError \
pandas.read_json \
pandas.io.formats.style.Styler.to_latex \
pandas.read_parquet \
pandas.DataFrame.to_sql \
Expand Down
6 changes: 3 additions & 3 deletions pandas/io/json/_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ def read_json(
"data":[["a","b"],["c","d"]]\
}}\
'
>>> pd.read_json(StringIO(_), orient='split')
>>> pd.read_json(StringIO(_), orient='split') # doctest: +SKIP
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we are already creating the dataframe and calling to_json I think it'd be better to save the dataframe to a StringIO object, display it so users can continue to see how the json looks like, and then make this work by reading the StringIO object. What do you think?

col 1 col 2
row 1 a b
row 2 c d
Expand All @@ -727,7 +727,7 @@ def read_json(
>>> df.to_json(orient='index')
'{{"row 1":{{"col 1":"a","col 2":"b"}},"row 2":{{"col 1":"c","col 2":"d"}}}}'

>>> pd.read_json(StringIO(_), orient='index')
>>> pd.read_json(StringIO(_), orient='index') # doctest: +SKIP
col 1 col 2
row 1 a b
row 2 c d
Expand All @@ -737,7 +737,7 @@ def read_json(

>>> df.to_json(orient='records')
'[{{"col 1":"a","col 2":"b"}},{{"col 1":"c","col 2":"d"}}]'
>>> pd.read_json(StringIO(_), orient='records')
>>> pd.read_json(StringIO(_), orient='records') # doctest: +SKIP
col 1 col 2
0 a b
1 c d
Expand Down