Skip to content

API: Change default for Index.union sort #25007

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
Prev Previous commit
Next Next commit
update test
  • Loading branch information
TomAugspurger committed Jan 29, 2019
commit d4bcc55a161c56f485b95fdbcfcff88344df47d4
2 changes: 1 addition & 1 deletion pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2268,7 +2268,7 @@ def union(self, other, sort=None):

.. versionadded:: 0.24.0

.. versionchanged:: 0.24.0
.. versionchanged:: 0.24.1

Changed the default `sort` to None, matching the
Copy link
Contributor

Choose a reason for hiding this comment

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

why is this being changed? this is certainly not a regression at all. This was the default behavior.

Copy link
Member

Choose a reason for hiding this comment

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

To be clear: no behaviour is changed. It was indeed the default, it stays the default. It's only the value that encodes the default that is changed (True -> None), so that True can mean something else (=always sort).

Copy link
Contributor

Choose a reason for hiding this comment

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

ok, maybe it should be more clear in the doc-string

behavior of pandas 0.23.4 and earlier.
Expand Down
9 changes: 5 additions & 4 deletions pandas/tests/indexes/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -856,19 +856,20 @@ def test_union_from_iterables(self, klass, sort):
tm.assert_index_equal(result, everything.sort_values())
assert tm.equalContents(result, everything)

@pytest.mark.parametrize("sort", [True, False])
@pytest.mark.parametrize("sort", [None, True, False])
def test_union_identity(self, sort):
# TODO: replace with fixturesult
first = self.strIndex[5:20]

union = first.union(first, sort=sort)
assert union is first
# i.e. identity is not preserved when sort is True
assert (union is first) is (not sort)

union = first.union([], sort=sort)
assert union is first
assert (union is first) is (not sort)

union = Index([]).union(first, sort=sort)
assert union is first
assert (union is first) is (not sort)

@pytest.mark.parametrize("first_list", [list('ba'), list()])
@pytest.mark.parametrize("second_list", [list('ab'), list()])
Expand Down