Skip to content

TST: Use sort fixture in more places #32292

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
Show file tree
Hide file tree
Changes from all 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
3 changes: 0 additions & 3 deletions pandas/tests/indexes/base_class/test_setops.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ def test_union_sort_other_incomparable_true(self):
with pytest.raises(TypeError, match=".*"):
idx.union(idx[:1], sort=True)

@pytest.mark.parametrize("sort", [None, False])
def test_intersection_base(self, sort):
# (same results for py2 and py3 but sortedness not tested elsewhere)
index = Index([0, "a", 1, "b", 2, "c"])
Expand All @@ -103,7 +102,6 @@ def test_intersection_base(self, sort):
tm.assert_index_equal(result, expected)

@pytest.mark.parametrize("klass", [np.array, Series, list])
@pytest.mark.parametrize("sort", [None, False])
def test_intersection_different_type_base(self, klass, sort):
# GH 10149
index = Index([0, "a", 1, "b", 2, "c"])
Expand All @@ -123,7 +121,6 @@ def test_intersection_equal_sort(self):
tm.assert_index_equal(idx.intersection(idx, sort=False), idx)
tm.assert_index_equal(idx.intersection(idx, sort=None), idx)

@pytest.mark.parametrize("sort", [None, False])
def test_difference_base(self, sort):
# (same results for py2 and py3 but sortedness not tested elsewhere)
index = Index([0, "a", 1, "b", 2, "c"])
Expand Down
1 change: 0 additions & 1 deletion pandas/tests/indexes/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,6 @@ def test_union_base(self, indices):
with pytest.raises(TypeError, match=msg):
first.union([1, 2, 3])

@pytest.mark.parametrize("sort", [None, False])
def test_difference_base(self, sort, indices):
first = indices[2:]
second = indices[:4]
Expand Down
18 changes: 18 additions & 0 deletions pandas/tests/indexes/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import pytest


@pytest.fixture(params=[None, False])
def sort(request):
"""
Valid values for the 'sort' parameter used in the Index
setops methods (intersection, union, etc.)

Caution:
Don't confuse this one with the "sort" fixture used
for DataFrame.append or concat. That one has
parameters [True, False].

We can't combine them as sort=True is not permitted
in in the Index setops methods.
"""
return request.param
1 change: 0 additions & 1 deletion pandas/tests/indexes/datetimes/test_join.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ def test_join_utc_convert(self, join_type):
assert isinstance(result, DatetimeIndex)
assert result.tz.zone == "UTC"

@pytest.mark.parametrize("sort", [None, False])
def test_datetimeindex_union_join_empty(self, sort):
dti = date_range(start="1/1/2001", end="2/1/2001", freq="D")
empty = Index([])
Expand Down
18 changes: 0 additions & 18 deletions pandas/tests/indexes/datetimes/test_setops.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ class TestDatetimeIndexSetOps:
]

# TODO: moved from test_datetimelike; dedup with version below
@pytest.mark.parametrize("sort", [None, False])
def test_union2(self, sort):
everything = tm.makeDateIndex(10)
first = everything[:5]
Expand All @@ -42,7 +41,6 @@ def test_union2(self, sort):
tm.assert_index_equal(union, everything)

@pytest.mark.parametrize("box", [np.array, Series, list])
@pytest.mark.parametrize("sort", [None, False])
def test_union3(self, sort, box):
everything = tm.makeDateIndex(10)
first = everything[:5]
Expand All @@ -57,7 +55,6 @@ def test_union3(self, sort, box):
tm.assert_index_equal(result, expected)

@pytest.mark.parametrize("tz", tz)
@pytest.mark.parametrize("sort", [None, False])
def test_union(self, tz, sort):
rng1 = pd.date_range("1/1/2000", freq="D", periods=5, tz=tz)
other1 = pd.date_range("1/6/2000", freq="D", periods=5, tz=tz)
Expand Down Expand Up @@ -89,7 +86,6 @@ def test_union(self, tz, sort):
else:
tm.assert_index_equal(result_union, exp_notsorted)

@pytest.mark.parametrize("sort", [None, False])
def test_union_coverage(self, sort):
idx = DatetimeIndex(["2000-01-03", "2000-01-01", "2000-01-02"])
ordered = DatetimeIndex(idx.sort_values(), freq="infer")
Expand All @@ -100,7 +96,6 @@ def test_union_coverage(self, sort):
tm.assert_index_equal(result, ordered)
assert result.freq == ordered.freq

@pytest.mark.parametrize("sort", [None, False])
def test_union_bug_1730(self, sort):
rng_a = date_range("1/1/2012", periods=4, freq="3H")
rng_b = date_range("1/1/2012", periods=4, freq="4H")
Expand All @@ -113,7 +108,6 @@ def test_union_bug_1730(self, sort):
exp = DatetimeIndex(exp)
tm.assert_index_equal(result, exp)

@pytest.mark.parametrize("sort", [None, False])
def test_union_bug_1745(self, sort):
left = DatetimeIndex(["2012-05-11 15:19:49.695000"])
right = DatetimeIndex(
Expand All @@ -137,7 +131,6 @@ def test_union_bug_1745(self, sort):
exp = exp.sort_values()
tm.assert_index_equal(result, exp)

@pytest.mark.parametrize("sort", [None, False])
def test_union_bug_4564(self, sort):
from pandas import DateOffset

Expand All @@ -152,7 +145,6 @@ def test_union_bug_4564(self, sort):
exp = DatetimeIndex(exp)
tm.assert_index_equal(result, exp)

@pytest.mark.parametrize("sort", [None, False])
def test_union_freq_both_none(self, sort):
# GH11086
expected = bdate_range("20150101", periods=10)
Expand Down Expand Up @@ -188,7 +180,6 @@ def test_union_dataframe_index(self):
exp = pd.date_range("1/1/1980", "1/1/2012", freq="MS")
tm.assert_index_equal(df.index, exp)

@pytest.mark.parametrize("sort", [None, False])
def test_union_with_DatetimeIndex(self, sort):
i1 = Int64Index(np.arange(0, 20, 2))
i2 = date_range(start="2012-01-03 00:00:00", periods=10, freq="D")
Expand Down Expand Up @@ -218,7 +209,6 @@ def test_intersection2(self):
@pytest.mark.parametrize(
"tz", [None, "Asia/Tokyo", "US/Eastern", "dateutil/US/Pacific"]
)
@pytest.mark.parametrize("sort", [None, False])
def test_intersection(self, tz, sort):
# GH 4690 (with tz)
base = date_range("6/1/2000", "6/30/2000", freq="D", name="idx")
Expand Down Expand Up @@ -298,7 +288,6 @@ def test_intersection_bug_1708(self):
assert len(result) == 0

@pytest.mark.parametrize("tz", tz)
@pytest.mark.parametrize("sort", [None, False])
def test_difference(self, tz, sort):
rng_dates = ["1/2/2000", "1/3/2000", "1/1/2000", "1/4/2000", "1/5/2000"]

Expand All @@ -324,7 +313,6 @@ def test_difference(self, tz, sort):
expected = expected.sort_values()
tm.assert_index_equal(result_diff, expected)

@pytest.mark.parametrize("sort", [None, False])
def test_difference_freq(self, sort):
# GH14323: difference of DatetimeIndex should not preserve frequency

Expand All @@ -341,7 +329,6 @@ def test_difference_freq(self, sort):
tm.assert_index_equal(idx_diff, expected)
tm.assert_attr_equal("freq", idx_diff, expected)

@pytest.mark.parametrize("sort", [None, False])
def test_datetimeindex_diff(self, sort):
dti1 = date_range(freq="Q-JAN", start=datetime(1997, 12, 31), periods=100)
dti2 = date_range(freq="Q-JAN", start=datetime(1997, 12, 31), periods=98)
Expand All @@ -352,7 +339,6 @@ class TestBusinessDatetimeIndex:
def setup_method(self, method):
self.rng = bdate_range(START, END)

@pytest.mark.parametrize("sort", [None, False])
def test_union(self, sort):
# overlapping
left = self.rng[:10]
Expand Down Expand Up @@ -388,7 +374,6 @@ def test_union(self, sort):
the_union = self.rng.union(rng, sort=sort)
assert isinstance(the_union, DatetimeIndex)

@pytest.mark.parametrize("sort", [None, False])
def test_union_not_cacheable(self, sort):
rng = date_range("1/1/2000", periods=50, freq=Minute())
rng1 = rng[10:]
Expand Down Expand Up @@ -431,7 +416,6 @@ def test_intersection_bug(self):
result = a.intersection(b)
tm.assert_index_equal(result, b)

@pytest.mark.parametrize("sort", [None, False])
def test_month_range_union_tz_pytz(self, sort):
from pytz import timezone

Expand All @@ -449,7 +433,6 @@ def test_month_range_union_tz_pytz(self, sort):
early_dr.union(late_dr, sort=sort)

@td.skip_if_windows_python_3
@pytest.mark.parametrize("sort", [None, False])
def test_month_range_union_tz_dateutil(self, sort):
from pandas._libs.tslibs.timezones import dateutil_gettz

Expand All @@ -471,7 +454,6 @@ class TestCustomDatetimeIndex:
def setup_method(self, method):
self.rng = bdate_range(START, END, freq="C")

@pytest.mark.parametrize("sort", [None, False])
def test_union(self, sort):
# overlapping
left = self.rng[:10]
Expand Down
6 changes: 0 additions & 6 deletions pandas/tests/indexes/interval/test_setops.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@ def name(request):
return request.param


@pytest.fixture(params=[None, False])
def sort(request):
return request.param


def monotonic_index(start, end, dtype="int64", closed="right"):
return IntervalIndex.from_breaks(np.arange(start, end, dtype=dtype), closed=closed)

Expand Down Expand Up @@ -153,7 +148,6 @@ def test_symmetric_difference(self, closed, sort):
@pytest.mark.parametrize(
"op_name", ["union", "intersection", "difference", "symmetric_difference"]
)
@pytest.mark.parametrize("sort", [None, False])
def test_set_incompatible_types(self, closed, op_name, sort):
index = monotonic_index(0, 11, closed=closed)
set_op = getattr(index, op_name)
Expand Down
8 changes: 0 additions & 8 deletions pandas/tests/indexes/multi/test_setops.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@


@pytest.mark.parametrize("case", [0.5, "xxx"])
@pytest.mark.parametrize("sort", [None, False])
@pytest.mark.parametrize(
"method", ["intersection", "union", "difference", "symmetric_difference"]
)
Expand All @@ -18,7 +17,6 @@ def test_set_ops_error_cases(idx, case, sort, method):
getattr(idx, method)(case, sort=sort)


@pytest.mark.parametrize("sort", [None, False])
@pytest.mark.parametrize("klass", [MultiIndex, np.array, Series, list])
def test_intersection_base(idx, sort, klass):
first = idx[2::-1] # first 3 elements reversed
Expand All @@ -39,7 +37,6 @@ def test_intersection_base(idx, sort, klass):
first.intersection([1, 2, 3], sort=sort)


@pytest.mark.parametrize("sort", [None, False])
@pytest.mark.parametrize("klass", [MultiIndex, np.array, Series, list])
def test_union_base(idx, sort, klass):
first = idx[::-1]
Expand All @@ -60,7 +57,6 @@ def test_union_base(idx, sort, klass):
first.union([1, 2, 3], sort=sort)


@pytest.mark.parametrize("sort", [None, False])
def test_difference_base(idx, sort):
second = idx[4:]
answer = idx[:4]
Expand All @@ -83,7 +79,6 @@ def test_difference_base(idx, sort):
idx.difference([1, 2, 3], sort=sort)


@pytest.mark.parametrize("sort", [None, False])
def test_symmetric_difference(idx, sort):
first = idx[1:]
second = idx[:-1]
Expand Down Expand Up @@ -123,7 +118,6 @@ def test_empty(idx):
assert idx[:0].empty


@pytest.mark.parametrize("sort", [None, False])
def test_difference(idx, sort):

first = idx
Expand Down Expand Up @@ -234,7 +228,6 @@ def test_difference_sort_incomparable_true():
idx.difference(other, sort=True)


@pytest.mark.parametrize("sort", [None, False])
def test_union(idx, sort):
piece1 = idx[:5][::-1]
piece2 = idx[3:]
Expand Down Expand Up @@ -270,7 +263,6 @@ def test_union(idx, sort):
# assert result.equals(result2)


@pytest.mark.parametrize("sort", [None, False])
def test_intersection(idx, sort):
piece1 = idx[:5][::-1]
piece2 = idx[3:]
Expand Down
6 changes: 0 additions & 6 deletions pandas/tests/indexes/period/test_setops.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ def _permute(obj):


class TestPeriodIndex:
@pytest.mark.parametrize("sort", [None, False])
def test_union(self, sort):
# union
other1 = period_range("1/1/2000", freq="D", periods=5)
Expand Down Expand Up @@ -134,7 +133,6 @@ def test_union(self, sort):
expected = expected.sort_values()
tm.assert_index_equal(result_union, expected)

@pytest.mark.parametrize("sort", [None, False])
def test_union_misc(self, sort):
index = period_range("1/1/2000", "1/20/2000", freq="D")

Expand Down Expand Up @@ -165,7 +163,6 @@ def test_union_dataframe_index(self):
exp = period_range("1/1/1980", "1/1/2012", freq="M")
tm.assert_index_equal(df.index, exp)

@pytest.mark.parametrize("sort", [None, False])
def test_intersection(self, sort):
index = period_range("1/1/2000", "1/20/2000", freq="D")

Expand All @@ -190,7 +187,6 @@ def test_intersection(self, sort):
with pytest.raises(IncompatibleFrequency):
index.intersection(index3, sort=sort)

@pytest.mark.parametrize("sort", [None, False])
def test_intersection_cases(self, sort):
base = period_range("6/1/2000", "6/30/2000", freq="D", name="idx")

Expand Down Expand Up @@ -259,7 +255,6 @@ def test_intersection_cases(self, sort):
result = rng.intersection(rng[0:0])
assert len(result) == 0

@pytest.mark.parametrize("sort", [None, False])
def test_difference(self, sort):
# diff
period_rng = ["1/3/2000", "1/2/2000", "1/1/2000", "1/5/2000", "1/4/2000"]
Expand Down Expand Up @@ -324,7 +319,6 @@ def test_difference(self, sort):
expected = expected.sort_values()
tm.assert_index_equal(result_difference, expected)

@pytest.mark.parametrize("sort", [None, False])
def test_difference_freq(self, sort):
# GH14323: difference of Period MUST preserve frequency
# but the ability to union results must be preserved
Expand Down
2 changes: 0 additions & 2 deletions pandas/tests/indexes/ranges/test_setops.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@


class TestRangeIndexSetOps:
@pytest.mark.parametrize("sort", [None, False])
def test_intersection(self, sort):
# intersect with Int64Index
index = RangeIndex(start=0, stop=20, step=2)
Expand Down Expand Up @@ -79,7 +78,6 @@ def test_intersection(self, sort):
expected = RangeIndex(0, 0, 1)
tm.assert_index_equal(result, expected)

@pytest.mark.parametrize("sort", [False, None])
def test_union_noncomparable(self, sort):
# corner case, non-Int64Index
index = RangeIndex(start=0, stop=20, step=2)
Expand Down
Loading