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 5 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
8 changes: 4 additions & 4 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -9379,7 +9379,7 @@ def _append(

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

Parameters
----------
other : DataFrame, Series, or list of DataFrame
other : DataFrame, Series, or list of either of these
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this should say "or list of DataFrames, Series, or both". "Either of these" implies that it has to be all one type.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I went with "or a list containing any combination of DataFrames and Series", if that's okay

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 @@ -9537,7 +9537,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 @@ -9583,7 +9583,7 @@ def _join_compat(
"Suffixes not supported when joining multiple DataFrames"
)

frames = [self] + list(other)
frames = [self] + list(cast(Sequence[DataFrame | Series], other))

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

Expand Down
2 changes: 1 addition & 1 deletion pandas/core/reshape/concat.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def concat(

@deprecate_nonkeyword_arguments(version=None, allowed_args=["objs"])
def concat(
objs: Iterable[NDFrame] | Mapping[HashableT, NDFrame],
objs: Iterable[NDFrame | DataFrame | Series] | Mapping[HashableT, NDFrame],
axis: Axis = 0,
join: str = "outer",
ignore_index: bool = False,
Expand Down
7 changes: 7 additions & 0 deletions pandas/tests/frame/methods/test_join.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,13 @@ def test_join_left_sequence_non_unique_index():
tm.assert_frame_equal(joined, expected)


def test_join_list_series(float_frame):
left = float_frame.A.to_frame()
right = [float_frame.B, float_frame[["C", "D"]]]
result = left.join(right)
assert result.equals(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