Skip to content

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

Merged
merged 1 commit into from
Nov 7, 2015

Conversation

max-sixty
Copy link
Contributor

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

>>> 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
Copy link
Contributor

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 >>>)

@jreback jreback added the Docs label Oct 28, 2015
@jreback jreback added this to the 0.17.1 milestone Oct 28, 2015
@max-sixty max-sixty force-pushed the panel-apply-docs branch 2 times, most recently from b8cebc3 to e6d067d Compare October 29, 2015 23:39
@max-sixty
Copy link
Contributor Author

@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))
Copy link
Member

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)

@max-sixty
Copy link
Contributor Author

@jorisvandenbossche
Thanks - I edited. I think we also can't just do panel.apply, but instead need the full expression pd.Panel(pd.np.random.rand(4,3,2)).apply(pd.np.sqrt). Tell me if I'm wrong though

>>> 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
Copy link
Member

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

@jorisvandenbossche
Copy link
Member

@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

>>> p = pd.Panel(np.random.rand(4,3,2))
>>> p.apply(np.sqrt)

Equivalent to p.sum(1), returning a DataFrame

>>> p.apply(lambda x: x.sum(), axis=1)

Equivalent to previous:

>>> p.apply(lambda x: x.sum(), axis='minor')

....


returns a Panel with the square root of each element

>>> pd.Panel(pd.np.random.rand(4,3,2)).apply(pd.np.sqrt)
Copy link
Member

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

@max-sixty
Copy link
Contributor Author

@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
Copy link
Member

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!

@max-sixty
Copy link
Contributor Author

@jorisvandenbossche I accidentally PEP8-ed the whole file. Shall I undo, or is that actually helpful?

jreback added a commit that referenced this pull request Nov 7, 2015
DOC: Improvements in panel apply docstring
@jreback jreback merged commit 8727182 into pandas-dev:master Nov 7, 2015
@jreback
Copy link
Contributor

jreback commented Nov 7, 2015

@MaximilianR yeh, normally want to do PEP stuff in separate PR's as confusing what is actually changed, but ok.

@max-sixty max-sixty deleted the panel-apply-docs branch November 7, 2015 17:25
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.

3 participants