Skip to content

BUG: Concatenation warning still appears with sort=False #27702

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 9 commits into from
Aug 4, 2019
Merged
Show file tree
Hide file tree
Changes from 3 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
8 changes: 6 additions & 2 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -7217,10 +7217,14 @@ def _join_compat(
# join indexes only using concat
if can_concat:
if how == "left":
res = concat(frames, axis=1, join="outer", verify_integrity=True)
res = concat(
frames, axis=1, join="outer", verify_integrity=True, sort=sort
)
return res.reindex(self.index, copy=False)
else:
return concat(frames, axis=1, join=how, verify_integrity=True)
return concat(
Copy link
Contributor

Choose a reason for hiding this comment

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

I suspect that this branch is under-tested... Could you update your new test to also assert the result of the concat operation?

frames, axis=1, join=how, verify_integrity=True, sort=sort
)

joined = frames[0]

Expand Down
31 changes: 31 additions & 0 deletions pandas/tests/frame/test_join.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ def right():
return DataFrame({"b": [300, 100, 200]}, index=[3, 1, 2])


@pytest.fixture(params=[True, False, None])
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps just define this as a pytest.mark.parametrize on the test itself? Since we only use it once that's a bit clearer.

def sort_kw(request):
"""Boolean sort keyword for join.
Includes the default of None.
"""
return request.param


@pytest.mark.parametrize(
"how, sort, expected",
[
Expand Down Expand Up @@ -193,3 +201,26 @@ def test_join_left_sequence_non_unique_index():
)

tm.assert_frame_equal(joined, expected)


def test_suppress_future_warning_with_sort_kw(sort_kw):
a = DataFrame(
{"col1": [1, 2, 3, 4, 5], "col2": [6, 7, 8, 9, 10]},
index=["a", "c", "e", "f", "i"],
)

b = DataFrame(
{"col4": [1, 2, 3, 4, 5], "col3": [1, 2, 3, 4, 5]},
index=["a", "b", "c", "d", "e"],
)

c = DataFrame({"col5": [1, 2, 3, 4, 5]}, index=["f", "g", "h", "i", "j"])

if sort_kw is None:
# only warn if not explicitly specified
ctx = tm.assert_produces_warning(FutureWarning, check_stacklevel=False)
else:
ctx = tm.assert_produces_warning(None, check_stacklevel=False)

with ctx:
a.join([b, c], sort=sort_kw)