Skip to content

Added example for Dataframe.align #43225

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

Conversation

oovk
Copy link
Contributor

@oovk oovk commented Aug 26, 2021

@MarcoGorelli MarcoGorelli self-requested a review August 26, 2021 14:07
Copy link
Member

@phofl phofl left a comment

Choose a reason for hiding this comment

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

small comment, otherwise lgtm. Maybe adding one for axis=0?

3 60 70 80 90
4 600 700 800 900

>>> a1, a2 = left.align(right,
Copy link
Member

Choose a reason for hiding this comment

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

Formatting looks a bit odd here, does this fit into one row?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It looks like this, I'm not really sure about linting styles, not able to figure out why autopep8 is not working for me.☹️
image

Copy link
Member

Choose a reason for hiding this comment

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

autopep8 is not working for me

This is a docstring, autopep8 runs on code. And second, pandas doesn't use the autopep8 formatter, but the black formatter

@oovk oovk requested a review from phofl August 28, 2021 08:11
Comment on lines 8552 to 8562
>>> a1
D B E A
2 6.0 7.0 8.0 9.0
3 NaN NaN NaN NaN
4 NaN NaN NaN NaN

>>> a2
A B C D
2 10 20 30 40
3 60 70 80 90
4 600 700 800 900
Copy link
Member

Choose a reason for hiding this comment

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

these results don't look correct

also, the formatting's off so it won't pass the checks - one way to fix this would be to paste your code in another file, run black on it, and then paste it back here. Or paste the entire docstring in another file and run blackdoc on it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When I run python scripts/validate_docstrings.py pandas.DataFrame.align I get these errors wrt example being not correct.
Screenshot 2021-08-28 at 5 53 45 PM

But when I checked the example in dev version the output differs.
Screenshot 2021-08-28 at 5 52 59 PM

PTAL!

Copy link
Member

Choose a reason for hiding this comment

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

you've got join='right' in your docstring

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ohh, sry my bad😅

@oovk oovk requested a review from MarcoGorelli August 28, 2021 13:22
Copy link
Member

@MarcoGorelli MarcoGorelli left a comment

Choose a reason for hiding this comment

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

this won't pass CI checks - I suggest you copy and paste the code you've written to a new text file, run black and flake8 on it, then copy the code back to the docstrings

@oovk
Copy link
Contributor Author

oovk commented Aug 28, 2021

Soo, we use blackdocfor doc formatting right🤔? I was really confused between black n blackdoc.😕

Copy link
Member

@MarcoGorelli MarcoGorelli left a comment

Choose a reason for hiding this comment

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

couple more things

one on naming, the other: can you add a little explanation in between the examples? So, after you've shown the axis=1 example, you can write something like "We can also align on the index" and then show the axis=0 example (see https://pandas.pydata.org/pandas-docs/stable/development/contributing_docstring.html#conventions-for-the-examples)

Rest looks good! 👍

Comment on lines 8514 to 8535
>>> left = pd.DataFrame(
... [[1, 2, 3, 4], [6, 7, 8, 9]], columns=["D", "B", "E", "A"], index=[1, 2]
... )

>>> right = pd.DataFrame(
... [[10, 20, 30, 40], [60, 70, 80, 90], [600, 700, 800, 900]],
... columns=["A", "B", "C", "D"],
... index=[2, 3, 4],
... )

>>> left
D B E A
1 1 2 3 4
2 6 7 8 9

>>> right
A B C D
2 10 20 30 40
3 60 70 80 90
4 600 700 800 900

>>> a1, a2 = left.align(right, join="outer", axis=1)
Copy link
Member

Choose a reason for hiding this comment

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

last thing - for consistency with the arguments, can we name the original dataframes df and other, and then the results left and right? So

Suggested change
>>> left = pd.DataFrame(
... [[1, 2, 3, 4], [6, 7, 8, 9]], columns=["D", "B", "E", "A"], index=[1, 2]
... )
>>> right = pd.DataFrame(
... [[10, 20, 30, 40], [60, 70, 80, 90], [600, 700, 800, 900]],
... columns=["A", "B", "C", "D"],
... index=[2, 3, 4],
... )
>>> left
D B E A
1 1 2 3 4
2 6 7 8 9
>>> right
A B C D
2 10 20 30 40
3 60 70 80 90
4 600 700 800 900
>>> a1, a2 = left.align(right, join="outer", axis=1)
>>> df = pd.DataFrame(
... [[1, 2, 3, 4], [6, 7, 8, 9]], columns=["D", "B", "E", "A"], index=[1, 2]
... )
>>> other = pd.DataFrame(
... [[10, 20, 30, 40], [60, 70, 80, 90], [600, 700, 800, 900]],
... columns=["A", "B", "C", "D"],
... index=[2, 3, 4],
... )
>>> df
D B E A
1 1 2 3 4
2 6 7 8 9
>>> other
A B C D
2 10 20 30 40
3 60 70 80 90
4 600 700 800 900
>>> left, right = left.align(right, join="outer", axis=1)

(likewise for the axis=0 example)

Copy link
Member

@MarcoGorelli MarcoGorelli left a comment

Choose a reason for hiding this comment

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

thanks @oovk

@MarcoGorelli MarcoGorelli added this to the 1.4 milestone Aug 28, 2021
@MarcoGorelli MarcoGorelli merged commit f6ae271 into pandas-dev:master Aug 28, 2021
@MarcoGorelli
Copy link
Member

Soo, we use blackdocfor doc formatting rightthinking? I was really confused between black n blackdoc.confused

docstring are formatted with a custom check which runs flake8, but it doesn't autoformat them, that's something we need to do manually unfortunately. I'd like to make it automatic though, it's kinda on my todo list

feefladder pushed a commit to feefladder/pandas that referenced this pull request Sep 7, 2021
* added example for Dataframe.align

* added example for axis=0 param

* changes in align example

* passed linting checks

* made requested changes

* fixup

Co-authored-by: Marco Gorelli <[email protected]>
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.

DOC add example to align
3 participants