-
-
Notifications
You must be signed in to change notification settings - Fork 18.8k
DOC: Improvements in panel apply docstring #11449
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
>>> panel.apply(np.sqrt) # returns a Panel | ||
>>> panel.apply(lambda x: x.sum(), axis=1) # equivalent to p.sum(1), returning DataFrame | ||
>>> panel.apply(lambda x: x.sum(), axis='minor') # equivalent to previous | ||
>>> panel.apply(lambda x: x.shape, axis=(0,1)) # return the shapes of each DataFrame over axis 2, in Series |
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.
to avoid going to long, add on a separate line (e.g. comment before), skipping a line between examples (and it doesn't need to be a comment as text is not executed unless at >>>)
b8cebc3
to
e6d067d
Compare
@jreback green |
equivalent to previous | ||
>>> panel.apply(lambda x: x.sum(), axis='minor') | ||
return the shapes of each DataFrame over axis 2, as a Series | ||
>>> panel.apply(lambda x: x.shape, axis=(0,1)) |
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.
I think there have to be blank lines between the code parts (>>>
) and the explanations in between to render OK
(see '12. Examples' in https://github.com/numpy/numpy/blob/master/doc/HOWTO_DOCUMENT.rst.txt#sections)
e6d067d
to
0cee5f9
Compare
@jorisvandenbossche |
>>> p.apply(lambda x: x.sum(), axis=1) # equiv to p.sum(1) | ||
>>> p.apply(lambda x: x.sum(), axis=2) # equiv to p.sum(2) | ||
|
||
returns a Panel with the square root of each element |
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.
These lines should not have an indentation compared to the other lines
@MaximilianR In theory, a full expression is not needed as this code is at the moment never run in order to build the docs (as is the case with the tutorials), but it is always nice to have full examples so people can copy paste it. For layout, I think something like this is best (once define the variable, and then use it instead repeating the creation):
|
|
||
returns a Panel with the square root of each element | ||
|
||
>>> pd.Panel(pd.np.random.rand(4,3,2)).apply(pd.np.sqrt) |
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.
Other comment: it is not needed to use pd.np
, you can just use the common np
numpy import
0cee5f9
to
2957bbf
Compare
@jorisvandenbossche updated |
|
||
>>> p.apply(lambda x: x.sum(), axis='minor') | ||
|
||
Return the shapes of each DataFrame over axis 2 (i.e the shapes of items x major), as a Series |
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.
you just missed one here. For the rest looks very good!
2957bbf
to
bd896da
Compare
@jorisvandenbossche I accidentally PEP8-ed the whole file. Shall I undo, or is that actually helpful? |
DOC: Improvements in panel apply docstring
@MaximilianR yeh, normally want to do PEP stuff in separate PR's as confusing what is actually changed, but ok. |
Not sure what the bar is for a PR here - this is a mild but meaningful improvement - in particular re the option to supply numbers & a tuple - by no means perfect though