Skip to content

update fix ignored sort in api.py and add test #43833

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
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
update fix ignored sort in api.py and add test
  • Loading branch information
CloseChoice committed Oct 1, 2021
commit b50dcb507bb1c635aff302d700b18f35daefbee9
7 changes: 5 additions & 2 deletions pandas/core/indexes/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,10 @@ def union_indexes(indexes, sort: bool = True) -> Index:
if len(indexes) == 1:
result = indexes[0]
if isinstance(result, list):
result = Index(sorted(result))
if sort:
result = Index(sorted(result))
else:
result = Index(result)
return result

indexes, kind = _sanitize_and_check(indexes)
Expand Down Expand Up @@ -219,7 +222,7 @@ def conv(i):
return result.union_many(indexes[1:])
else:
for other in indexes[1:]:
result = result.union(other)
result = result.union(other, sort=None if sort else False)
return result
elif kind == "array":
index = indexes[0]
Expand Down
8 changes: 8 additions & 0 deletions pandas/tests/arrays/integer/test_concat.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,11 @@ def test_concat_series_with_numpy(to_concat_dtypes, result_dtype):
result = pd.concat([s2, s1], ignore_index=True)
expected = pd.Series([0, 1, 0, 1, pd.NA], dtype=object).astype(result_dtype)
tm.assert_series_equal(result, expected)

def test_concat_frame_with_sort_false():
Copy link
Contributor

Choose a reason for hiding this comment

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

can you move to pandas/tests/reshape/concat/test_sort.py

put near simliar tests

result = pd.concat([pd.DataFrame({i: i}, index=[i]) for i in range(2, 0, -1)], sort=False)
expected = pd.DataFrame([[2, np.nan], [np.nan, 1]], index=[2,1], columns=[2,1])
import ipdb; ipdb.set_trace()

tm.assert_frame_equal(result, expected)