Skip to content

DOC: Format more code blocks #36734

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

Merged
merged 4 commits into from
Oct 1, 2020
Merged

DOC: Format more code blocks #36734

merged 4 commits into from
Oct 1, 2020

Conversation

dsaxton
Copy link
Member

@dsaxton dsaxton commented Sep 30, 2020

Actually, contrary to #36700 (comment) there is quite a lot more clean up to do (so maybe could make for some good first issues @simonjayhawkins), it's just that other docs contain blocks that blacken-docs can't parse (e.g., raw output or ipython code containing magic commands). A workaround is to comment them out, parse the doc, and then uncomment (the commented blocks would then have to be edited manually).

Is it possible to render blocks like this as pure code in rst which are allowed to raise?

   .. code-block:: python

       >>> pd.DataFrame(np.random.randn(10, 2)).to_hdf('test_fixed.h5', 'df')
       >>> pd.read_hdf('test_fixed.h5', 'df', where='index>5')
       TypeError: cannot pass a where specification when reading a fixed format.
                  this store must be selected in its entirety

@dsaxton dsaxton marked this pull request as ready for review September 30, 2020 01:58
@jreback jreback added the Docs label Sep 30, 2020
@jreback
Copy link
Contributor

jreback commented Sep 30, 2020

Actually, contrary to #36700 (comment) there is quite a lot more clean up to do (so maybe could make for some good first issues @simonjayhawkins ), it's just that other docs contain blocks that blacken-docs can't parse (e.g., raw output or ipython code containing magic commands). A workaround is to comment them out, parse the doc, and then uncomment (the commented blocks would then have to be edited manually).

Is it possible to render blocks like this as pure code in rst which are allowed to raise?

   .. code-block:: python

       >>> pd.DataFrame(np.random.randn(10, 2)).to_hdf('test_fixed.h5', 'df')
       >>> pd.read_hdf('test_fixed.h5', 'df', where='index>5')
       TypeError: cannot pass a where specification when reading a fixed format.
                  this store must be selected in its entirety

yes you can add :okexcept: though to be honest it doesn't look as nice I think (maybe there is a way to limit the traceback)

Copy link
Member

@WillAyd WillAyd left a comment

Choose a reason for hiding this comment

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

lgtm

@WillAyd WillAyd added this to the 1.2 milestone Sep 30, 2020
@jreback jreback merged commit 2042bbf into pandas-dev:master Oct 1, 2020
@jreback
Copy link
Contributor

jreback commented Oct 1, 2020

thanks @dsaxton

@dsaxton dsaxton deleted the more-doc-clean-up branch October 1, 2020 01:18
'a,b,2\n'
'c,d,3')

data = "col1,col2,col3\na,b,1\na,b,2\nc,d,3"
Copy link
Member

Choose a reason for hiding this comment

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

IMO this is not an improvement for the specific purpuse here: reading a csv file. To visualize how the csv file looks, the way it was before is better I think. Could also use multi-line string """, which is maybe more "black-proof"

Copy link
Member

Choose a reason for hiding this comment

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

(and the same for all the ones below)

df = pd.read_csv(StringIO(data),
dtype={'b': object, 'c': np.float64, 'd': 'Int64'})
df["a"][0]
df = pd.read_csv(StringIO(data), dtype={"b": object, "c": np.float64, "d": "Int64"})
Copy link
Member

Choose a reason for hiding this comment

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

Also, we should not use black's default line length limit of 88, because that will not fit in the code block width of the doc page. For example, this line is 85, and only fits exactly. So anything bigger will cause overflow/scrollbar.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah I was wondering about this afterwards, will work on fixing these

kesmit13 pushed a commit to kesmit13/pandas that referenced this pull request Nov 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants