-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
DOC: Fix examples in documentation #31472
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
Conversation
Hello @MomIsBestFriend! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found: There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻 Comment last updated at 2020-02-27 17:35:24 UTC |
pandas/core/generic.py
Outdated
"pandas_version": "0.20.0"}, | ||
"data": [{"index": "row 1", "col 1": "a", "col 2": "b"}, | ||
{"index": "row 2", "col 1": "c", "col 2": "d"}]}' | ||
'{"schema":{"fields":[{"name":"index","type":"string"},{"name":"col 1","type":"string"},{"name":"col 2","type":"string"}],"primaryKey":["index"],"pandas_version":"0.20.0"},"data":[{"index":"row 1","col 1":"a","col 2":"b"},{"index":"row 2","col 1":"c","col 2":"d"}]}' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because of lines like these (and basically every other output line, that's received by df.to_json()
), I think it's a good idea that we include a "pprint" example under each one, so it will look somewhat like this:
def example():
"""
Examples
--------
Encoding with table schema
>>> df = pd.DataFrame(
... [["a", "b"], ["c", "d"]],
... index=["row 1", "row 2"],
... columns=["col 1", "col 2"],
... )
>>> df.to_json(orient='table')
'{"schema":{"fields":[{"name":"index","type":"string"},{"name":"col 1","type":"string"},{"name":"col 2","type":"string"}],"primaryKey":["index"],"pandas_version":"0.20.0"},"data":[{"index":"row 1","col 1":"a","col 2":"b"},{"index":"row 2","col 1":"c","col 2":"d"}]}'
Pretty print version:
>>> import json
>>> result = df.to_json(orient="table")
>>> parsed = json.loads(result)
>>> json.dumps(parsed, indent=4)
{
"schema": {
"fields": [
{
"name": "index",
"type": "string"
},
{
"name": "col 1",
"type": "string"
},
{
"name": "col 2",
"type": "string"
}
],
"primaryKey": [
"index"
],
"pandas_version": "0.20.0"
},
"data": [
{
"index": "row 1",
"col 1": "a",
"col 2": "b"
},
{
"index": "row 2",
"col 1": "c",
"col 2": "d"
}
]
}
"""
Flake8 errors in CI: ##[error]./pandas/core/generic.py:2217:89:E501:line too long (94 > 88 characters) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also pls merge master
pandas/core/generic.py
Outdated
"index":["row 1","row 2"], | ||
"data":[["a","b"],["c","d"]]}' | ||
'{"columns":["col 1","col 2"],\ | ||
"index":["row 1","row 2"],\ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you use ... instead here?
pandas/core/generic.py
Outdated
"data": [{"index": "row 1", "col 1": "a", "col 2": "b"}, | ||
{"index": "row 2", "col 1": "c", "col 2": "d"}]}' | ||
'{"schema":{"fields":[{"name":"index","type":"string"},\ | ||
{"name":"col 1","type":"string"},{"name":"col 2","type":"string"}],\ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you use ... here? (else could do a json prettify, e.g. json.dump(...., indent=4)
freq 2 | ||
first 2000-01-01 00:00:00 | ||
last 2010-01-01 00:00:00 | ||
count 3 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are these on the doctest list that we check?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since 4d66fa8 they are.
pandas/core/generic.py
Outdated
@@ -9589,16 +9685,16 @@ def describe( | |||
|
|||
Excluding numeric columns from a ``DataFrame`` description. | |||
|
|||
>>> df.describe(exclude=[np.number]) | |||
>>> df.describe(exclude=[np.number]) # doctest: +SKIP |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How come you are adding doctest skips opposed to our current pytest -k approach? Think we should be consistent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem with describe, is that the output can be random, If you know how to skip a specific line in the output, it would be great!
Restarting azure |
A bit unsure about this, but I think it's reasonable. At least we test all what we can test. You have conflicts to fix. Also, for inline comments (with Also, why |
Thanks for the fixes @MomIsBestFriend. About the @jreback, if you want to have another look and see if your comments were addressed... |
I haven't got it to work without the skip maybe one of the core developers knows something? |
Do you know what was the error? |
Thanks for fixing those @MomIsBestFriend. Do you mind opening an issue for the |
black pandas
git diff upstream/master -u -- "*.py" | flake8 --diff