8000 API: Change default for Index.union sort by TomAugspurger · Pull Request #25007 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

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
multi
  • Loading branch information
TomAugspurger committed Jan 30, 2019
commit 8716f977433cfc62e6c279deadb5d285806c135c
14 changes: 6 additions & 8 deletions pandas/tests/indexes/multi/test_set_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,10 +253,8 @@ def test_intersection(idx, sort):

@pytest.mark.parametrize('slice_', [slice(None), slice(0)])
def test_union_sort_other_empty(slice_):
# https://github.com/pandas-dev/pandas/issues/24959
idx = pd.MultiIndex.from_product([[1, 0], ['a', 'b']])
# Two cases:
# 1. idx is other
# 2. other is empty

# default, sort=None
other = idx[slice_]
Expand All @@ -274,17 +272,17 @@ def test_union_sort_other_empty(slice_):


def test_union_sort_other_incomparable():
# https://github.com/pandas-dev/pandas/issues/24959
idx = pd.MultiIndex.from_product([[1, pd.Timestamp('2000')], ['a', 'b']])

# default, sort=None
# with tm.assert_produces_warning(RuntimeWarning):
result = idx.union(idx[:1])
tm.assert_index_equal(result, idx)

# sort=True
with pytest.raises(TypeError, match='Cannot compare'):
idx.union(idx[:1], sort=True)

# sort=False
result = idx.union(idx[:1], sort=False)
tm.assert_index_equal(result, idx)

# sort=True
with pytest.raises(TypeError, match='Cannot compare'):
idx.union(idx[:1], sort=True)
5 changes: 2 additions & 3 deletions pandas/tests/indexes/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -801,9 +801,7 @@ def test_union(self, sort):

@pytest.mark.parametrize('slice_', [slice(None), slice(0)])
def test_union_sort_other_special(self, slice_):
# Two cases:
# 1. idx is other
# 2. other is empty
# https://github.com/pandas-dev/pandas/issues/24959

idx = pd.Index([1, 0, 2])
# default, sort=None
Expand All @@ -820,6 +818,7 @@ def test_union_sort_other_special(self, slice_):
tm.assert_index_equal(result, expected)

def test_union_sort_other_incomparable(self):
# https://github.com/pandas-dev/pandas/issues/24959
idx = pd.Index([1, pd.Timestamp('2000')])
# default, sort=None
with tm.assert_produces_warning(RuntimeWarning):
Expand Down
0