Skip to content

DOC: added examples to align function's documentation #42129

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

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -8517,7 +8517,34 @@ def align(
"""

method = missing.clean_fill_method(method)
Copy link
Member

Choose a reason for hiding this comment

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

this shouldn't be removed

Copy link
Author

Choose a reason for hiding this comment

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

I addressed this in the last commit


"""
Examples
--------
>>> df1 = pd.DataFrame([[1,2,3,4], [6,7,8,9]],
columns=['D', 'B', 'E', 'A'], index=[1,2])
Comment on lines +8523 to +8524
Copy link
Member

Choose a reason for hiding this comment

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

also, the formatting's a bit strange here, it would be better to either format your example with black, or to align the arguments, like

Suggested change
>>> df1 = pd.DataFrame([[1,2,3,4], [6,7,8,9]],
columns=['D', 'B', 'E', 'A'], index=[1,2])
>>> df1 = pd.DataFrame(
... [[1,2,3,4], [6,7,8,9]],
... columns=['D', 'B', 'E', 'A'],
... index=[1, 2]
... )

(same for the other parts of the example)

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

>>> a1, a2 = df1.align(df2, 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.

perhaps call these left, right?

>>> a1
A B C D E
1 4 2 NaN 1 3
2 9 7 NaN 6 8
>>> a2
A B C D E
2 10 20 30 40 NaN
3 60 70 80 90 NaN
4 600 700 800 900 NaN

>>> a1, a2 = df1.align(df2, join='inner', axis=None)
Copy link
Member

Choose a reason for hiding this comment

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

likewise

>>> a1
D B A
2 6 7 9
>>> a2
D B A
2 40 20 10
"""

if broadcast_axis == 1 and self.ndim != other.ndim:
if isinstance(self, ABCSeries):
# this means other is a DataFrame, and we need to broadcast
Expand Down