-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
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
Added example for Dataframe.align #43225
Conversation
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.
small comment, otherwise lgtm. Maybe adding one for axis=0?
pandas/core/generic.py
Outdated
3 60 70 80 90 | ||
4 600 700 800 900 | ||
|
||
>>> a1, a2 = left.align(right, |
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.
Formatting looks a bit odd here, does this fit into one row?
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.
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.
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
…xample-Dataframe.align-doc merging
pandas/core/generic.py
Outdated
>>> 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 |
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 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
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.
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've got join='right'
in your docstring
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.
ohh, sry my bad😅
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.
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
Soo, we use |
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.
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! 👍
pandas/core/generic.py
Outdated
>>> 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) |
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.
last thing - for consistency with the arguments, can we name the original dataframes df
and other
, and then the results left
and right
? So
>>> 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)
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.
thanks @oovk
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 |
* 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]>
@MarcoGorelli