Skip to content

Update join docs for other param #46850

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 20 commits into from
Jul 21, 2022
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
22c54af
Update join docs for other param
multimeric Apr 23, 2022
36eec5b
Update type for _join_compat
multimeric Apr 23, 2022
48048db
Allow any iterable for join; test join for a list of series
multimeric May 27, 2022
7811306
Update type signature
multimeric May 27, 2022
bb002f8
Update pd.concat type, add cast() to make frame.join() work with mypy
multimeric May 28, 2022
436f5d3
Fix type union syntax
multimeric Jun 12, 2022
76ead79
NDFrame
multimeric Jun 12, 2022
b12f42e
Remove cast
multimeric Jun 12, 2022
e3c1fd3
Merge branch 'main' of github.com:pandas-dev/pandas into multimeric-p…
multimeric Jun 12, 2022
3b04d62
Fix mypy errors
multimeric Jun 15, 2022
f72bbdd
Merge branch 'main' of github.com:pandas-dev/pandas into multimeric-p…
multimeric Jun 15, 2022
7c1c113
Merge branch 'main' of github.com:pandas-dev/pandas into multimeric-p…
multimeric Jun 16, 2022
0a241c0
Code review
multimeric Jun 17, 2022
e83bace
Merge branch 'main' of github.com:pandas-dev/pandas into multimeric-p…
multimeric Jun 17, 2022
f72a5b5
Remove unnecessary assert
multimeric Jun 17, 2022
6d17dc9
Merge branch 'main' of github.com:pandas-dev/pandas into multimeric-p…
multimeric Jul 18, 2022
75436c8
Add comment explaining the cast
multimeric Jul 18, 2022
f48213f
Fix swapped order of cast comment
multimeric Jul 18, 2022
b79e66c
Remove full stop
multimeric Jul 19, 2022
4ba0ce0
Update pandas/core/frame.py
datapythonista Jul 21, 2022
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
13 changes: 9 additions & 4 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -9788,7 +9788,7 @@ def _append(

def join(
self,
other: DataFrame | Series,
other: DataFrame | Series | list[DataFrame | Series],
on: IndexLabel | None = None,
how: str = "left",
lsuffix: str = "",
Expand All @@ -9805,7 +9805,8 @@ def join(

Parameters
----------
other : DataFrame, Series, or list of DataFrame
other : DataFrame, Series, or a list containing any combination of DataFrames
and Series
Copy link
Member

Choose a reason for hiding this comment

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

I see it now; the linter is complaining about the "and" being lowercase as if it's the start the description. I'd hazard a guess that sphinx does too. I think we should make the type more consise:

DataFrame, Series, or a list of any combination of these

Index should be similar to one of the columns in this one. If a
Series is passed, its name attribute must be set, and that will be
used as the column name in the resulting joined DataFrame.
Expand Down Expand Up @@ -9961,7 +9962,7 @@ def join(

def _join_compat(
self,
other: DataFrame | Series,
other: DataFrame | Series | Iterable[DataFrame | Series],
on: IndexLabel | None = None,
how: str = "left",
lsuffix: str = "",
Expand Down Expand Up @@ -10010,7 +10011,11 @@ def _join_compat(
"Suffixes not supported when joining multiple DataFrames"
)

frames = [self] + list(other)
# Mypy thinks the RHS is a
# "Union[DataFrame, Series, Iterable[Union[DataFrame, Series]]]" whereas
# the LHS is an "Iterable[DataFrame]", but in reality both types are
# "Iterable[Union[DataFrame, Series]]" due to the if statements
frames = [cast("DataFrame | Series", self)] + list(other)

can_concat = all(df.index.is_unique for df in frames)

Expand Down
9 changes: 9 additions & 0 deletions pandas/tests/frame/methods/test_join.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,15 @@ def test_join_left_sequence_non_unique_index():
tm.assert_frame_equal(joined, expected)


def test_join_list_series(float_frame):
# GH#46850
# Join a DataFrame with a list containing both a Series and a DataFrame
left = float_frame.A.to_frame()
right = [float_frame.B, float_frame[["C", "D"]]]
result = left.join(right)
tm.assert_frame_equal(result, float_frame)


@pytest.mark.parametrize("sort_kw", [True, False])
def test_suppress_future_warning_with_sort_kw(sort_kw):
a = DataFrame({"col1": [1, 2]}, index=["c", "a"])
Expand Down