From 839059295f7427cdb67ca13a04cefd3364e0071b Mon Sep 17 00:00:00 2001 From: Brock Date: Tue, 24 Nov 2020 18:52:07 -0800 Subject: [PATCH 1/2] TST: tighten assert_index_equal checks --- pandas/_testing.py | 6 +++++- pandas/tests/arithmetic/test_numeric.py | 2 +- pandas/tests/frame/methods/test_reset_index.py | 2 +- pandas/tests/frame/test_constructors.py | 10 +++++----- pandas/tests/groupby/test_apply.py | 2 +- pandas/tests/indexes/common.py | 7 +++++-- pandas/tests/indexes/ranges/test_constructors.py | 4 ++-- pandas/tests/indexes/ranges/test_join.py | 8 ++++---- pandas/tests/indexes/ranges/test_range.py | 16 ++++++++-------- pandas/tests/indexes/ranges/test_setops.py | 12 ++++++------ pandas/tests/indexes/test_base.py | 5 +++-- pandas/tests/indexes/test_common.py | 3 ++- pandas/tests/indexes/test_setops.py | 8 ++++---- pandas/tests/reshape/concat/test_series.py | 4 ++-- pandas/tests/reshape/merge/test_join.py | 2 +- pandas/tests/series/test_constructors.py | 2 +- pandas/tests/window/test_pairwise.py | 10 ++++++++-- 17 files changed, 59 insertions(+), 44 deletions(-) diff --git a/pandas/_testing.py b/pandas/_testing.py index 87e99e520ab60..8d1466fde390f 100644 --- a/pandas/_testing.py +++ b/pandas/_testing.py @@ -982,7 +982,11 @@ def assert_categorical_equal( _check_isinstance(left, right, Categorical) if check_category_order: - assert_index_equal(left.categories, right.categories, obj=f"{obj}.categories") + # TODO: might be able to get exact=True if Categorical(RangeIndex) + # preserved RangeIndex categories + assert_index_equal( + left.categories, right.categories, obj=f"{obj}.categories", exact="equiv" + ) assert_numpy_array_equal( left.codes, right.codes, check_dtype=check_dtype, obj=f"{obj}.codes" ) diff --git a/pandas/tests/arithmetic/test_numeric.py b/pandas/tests/arithmetic/test_numeric.py index f4f258b559939..10835462b3289 100644 --- a/pandas/tests/arithmetic/test_numeric.py +++ b/pandas/tests/arithmetic/test_numeric.py @@ -1185,7 +1185,7 @@ def check_binop(self, ops, scalars, idxs): for scalar in scalars: result = op(idx, scalar) expected = op(Int64Index(idx), scalar) - tm.assert_index_equal(result, expected) + tm.assert_index_equal(result, expected, exact="equiv") def test_binops(self): ops = [ diff --git a/pandas/tests/frame/methods/test_reset_index.py b/pandas/tests/frame/methods/test_reset_index.py index 56fd633f5f22b..5864b547a552b 100644 --- a/pandas/tests/frame/methods/test_reset_index.py +++ b/pandas/tests/frame/methods/test_reset_index.py @@ -130,7 +130,7 @@ def test_reset_index(self, float_frame): float_frame.index.name = "index" deleveled = float_frame.reset_index() tm.assert_series_equal(deleveled["index"], Series(float_frame.index)) - tm.assert_index_equal(deleveled.index, Index(np.arange(len(deleveled)))) + tm.assert_index_equal(deleveled.index, Index(range(len(deleveled))), exact=True) # preserve column names float_frame.columns.name = "columns" diff --git a/pandas/tests/frame/test_constructors.py b/pandas/tests/frame/test_constructors.py index 27c12aa4fb3d1..a53517c904c18 100644 --- a/pandas/tests/frame/test_constructors.py +++ b/pandas/tests/frame/test_constructors.py @@ -352,7 +352,7 @@ def test_constructor_dict(self): # with dict of empty list and Series frame = DataFrame({"A": [], "B": []}, columns=["A", "B"]) - tm.assert_index_equal(frame.index, Index([], dtype=np.int64)) + tm.assert_index_equal(frame.index, RangeIndex(0), exact=True) # GH 14381 # Dict with None value @@ -811,14 +811,14 @@ def _check_basic_constructor(self, empty): # automatic labeling frame = DataFrame(mat) - tm.assert_index_equal(frame.index, pd.Int64Index(range(2))) - tm.assert_index_equal(frame.columns, pd.Int64Index(range(3))) + tm.assert_index_equal(frame.index, Index(range(2)), exact=True) + tm.assert_index_equal(frame.columns, Index(range(3)), exact=True) frame = DataFrame(mat, index=[1, 2]) - tm.assert_index_equal(frame.columns, pd.Int64Index(range(3))) + tm.assert_index_equal(frame.columns, Index(range(3)), exact=True) frame = DataFrame(mat, columns=["A", "B", "C"]) - tm.assert_index_equal(frame.index, pd.Int64Index(range(2))) + tm.assert_index_equal(frame.index, Index(range(2)), exact=True) # 0-length axis frame = DataFrame(empty((0, 3))) diff --git a/pandas/tests/groupby/test_apply.py b/pandas/tests/groupby/test_apply.py index 151ec03662335..c5b458c943529 100644 --- a/pandas/tests/groupby/test_apply.py +++ b/pandas/tests/groupby/test_apply.py @@ -387,7 +387,7 @@ def test_apply_frame_not_as_index_column_name(df): result = grouped.apply(len) expected = grouped.count().rename(columns={"C": np.nan}).drop(columns="D") # TODO: Use assert_frame_equal when column name is not np.nan (GH 36306) - tm.assert_index_equal(result.index, expected.index) + tm.assert_index_equal(result.index, expected.index, exact="equiv") tm.assert_numpy_array_equal(result.values, expected.values) diff --git a/pandas/tests/indexes/common.py b/pandas/tests/indexes/common.py index 3c0e4d83964c5..9a5bb6fdd23b3 100644 --- a/pandas/tests/indexes/common.py +++ b/pandas/tests/indexes/common.py @@ -529,6 +529,7 @@ def test_equals_op(self): # assuming the 2nd to last item is unique in the data item = index_a[-2] tm.assert_numpy_array_equal(index_a == item, expected3) + # For RangeIndex we can convert to Int64Index tm.assert_series_equal(series_a == item, Series(expected3)) def test_format(self): @@ -656,7 +657,8 @@ def test_map(self): expected = index result = index.map(lambda x: x) - tm.assert_index_equal(result, expected) + # For RangeIndex we convert to Int64Index + tm.assert_index_equal(result, expected, exact="equiv") @pytest.mark.parametrize( "mapper", @@ -680,7 +682,8 @@ def test_map_dictlike(self, mapper): expected = index result = index.map(identity) - tm.assert_index_equal(result, expected) + # For RangeIndex we convert to Int64Index + tm.assert_index_equal(result, expected, exact="equiv") # empty mappable expected = Index([np.nan] * len(index)) diff --git a/pandas/tests/indexes/ranges/test_constructors.py b/pandas/tests/indexes/ranges/test_constructors.py index f573da44e99b3..42128bf3d4cb1 100644 --- a/pandas/tests/indexes/ranges/test_constructors.py +++ b/pandas/tests/indexes/ranges/test_constructors.py @@ -27,7 +27,7 @@ def test_constructor(self, args, kwargs, start, stop, step, name): assert isinstance(result, RangeIndex) assert result.name is name assert result._range == range(start, stop, step) - tm.assert_index_equal(result, expected) + tm.assert_index_equal(result, expected, exact="equiv") def test_constructor_invalid_args(self): msg = "RangeIndex\\(\\.\\.\\.\\) must be called with integers" @@ -146,7 +146,7 @@ def test_constructor_corner(self): arr = np.array([1, 2, 3, 4], dtype=object) index = RangeIndex(1, 5) assert index.values.dtype == np.int64 - tm.assert_index_equal(index, Index(arr)) + tm.assert_index_equal(index, Index(arr), exact="equiv") # non-int raise Exception with pytest.raises(TypeError, match=r"Wrong type \"): diff --git a/pandas/tests/indexes/ranges/test_join.py b/pandas/tests/indexes/ranges/test_join.py index 76013d2b7a387..ab7f16098a85b 100644 --- a/pandas/tests/indexes/ranges/test_join.py +++ b/pandas/tests/indexes/ranges/test_join.py @@ -28,7 +28,7 @@ def test_join_outer(self): assert isinstance(res, Int64Index) assert not isinstance(res, RangeIndex) - tm.assert_index_equal(res, eres) + tm.assert_index_equal(res, eres, exact="equiv") tm.assert_numpy_array_equal(lidx, elidx) tm.assert_numpy_array_equal(ridx, eridx) @@ -41,7 +41,7 @@ def test_join_outer(self): assert isinstance(res, Int64Index) assert not isinstance(res, RangeIndex) - tm.assert_index_equal(res, eres) + tm.assert_index_equal(res, eres, exact="equiv") tm.assert_numpy_array_equal(lidx, elidx) tm.assert_numpy_array_equal(ridx, eridx) @@ -63,7 +63,7 @@ def test_join_inner(self): eridx = np.array([9, 7], dtype=np.intp) assert isinstance(res, Int64Index) - tm.assert_index_equal(res, eres) + tm.assert_index_equal(res, eres, exact="equiv") tm.assert_numpy_array_equal(lidx, elidx) tm.assert_numpy_array_equal(ridx, eridx) @@ -73,7 +73,7 @@ def test_join_inner(self): res, lidx, ridx = index.join(other, how="inner", return_indexers=True) assert isinstance(res, RangeIndex) - tm.assert_index_equal(res, eres) + tm.assert_index_equal(res, eres, exact="equiv") tm.assert_numpy_array_equal(lidx, elidx) tm.assert_numpy_array_equal(ridx, eridx) diff --git a/pandas/tests/indexes/ranges/test_range.py b/pandas/tests/indexes/ranges/test_range.py index cd3a0e7b2241c..377e355233ebc 100644 --- a/pandas/tests/indexes/ranges/test_range.py +++ b/pandas/tests/indexes/ranges/test_range.py @@ -419,38 +419,38 @@ def test_slice_specialised(self): # positive slice values index_slice = index[7:10:2] expected = Index(np.array([14, 18]), name="foo") - tm.assert_index_equal(index_slice, expected) + tm.assert_index_equal(index_slice, expected, exact="equiv") # negative slice values index_slice = index[-1:-5:-2] expected = Index(np.array([18, 14]), name="foo") - tm.assert_index_equal(index_slice, expected) + tm.assert_index_equal(index_slice, expected, exact="equiv") # stop overshoot index_slice = index[2:100:4] expected = Index(np.array([4, 12]), name="foo") - tm.assert_index_equal(index_slice, expected) + tm.assert_index_equal(index_slice, expected, exact="equiv") # reverse index_slice = index[::-1] expected = Index(index.values[::-1], name="foo") - tm.assert_index_equal(index_slice, expected) + tm.assert_index_equal(index_slice, expected, exact="equiv") index_slice = index[-8::-1] expected = Index(np.array([4, 2, 0]), name="foo") - tm.assert_index_equal(index_slice, expected) + tm.assert_index_equal(index_slice, expected, exact="equiv") index_slice = index[-40::-1] expected = Index(np.array([], dtype=np.int64), name="foo") - tm.assert_index_equal(index_slice, expected) + tm.assert_index_equal(index_slice, expected, exact="equiv") index_slice = index[40::-1] expected = Index(index.values[40::-1], name="foo") - tm.assert_index_equal(index_slice, expected) + tm.assert_index_equal(index_slice, expected, exact="equiv") index_slice = index[10::-1] expected = Index(index.values[::-1], name="foo") - tm.assert_index_equal(index_slice, expected) + tm.assert_index_equal(index_slice, expected, exact="equiv") @pytest.mark.parametrize("step", set(range(-5, 6)) - {0}) def test_len_specialised(self, step): diff --git a/pandas/tests/indexes/ranges/test_setops.py b/pandas/tests/indexes/ranges/test_setops.py index 9c9f5dbdf7e7f..99785a96326c1 100644 --- a/pandas/tests/indexes/ranges/test_setops.py +++ b/pandas/tests/indexes/ranges/test_setops.py @@ -26,28 +26,28 @@ def test_intersection(self, sort): other = RangeIndex(1, 6) result = index.intersection(other, sort=sort) expected = Index(np.sort(np.intersect1d(index.values, other.values))) - tm.assert_index_equal(result, expected) + tm.assert_index_equal(result, expected, exact="equiv") # intersect with decreasing RangeIndex other = RangeIndex(5, 0, -1) result = index.intersection(other, sort=sort) expected = Index(np.sort(np.intersect1d(index.values, other.values))) - tm.assert_index_equal(result, expected) + tm.assert_index_equal(result, expected, exact="equiv") # reversed (GH 17296) result = other.intersection(index, sort=sort) - tm.assert_index_equal(result, expected) + tm.assert_index_equal(result, expected, exact="equiv") # GH 17296: intersect two decreasing RangeIndexes first = RangeIndex(10, -2, -2) other = RangeIndex(5, -4, -1) expected = first.astype(int).intersection(other.astype(int), sort=sort) result = first.intersection(other, sort=sort).astype(int) - tm.assert_index_equal(result, expected) + tm.assert_index_equal(result, expected, exact="equiv") # reversed result = other.intersection(first, sort=sort).astype(int) - tm.assert_index_equal(result, expected) + tm.assert_index_equal(result, expected, exact="equiv") index = RangeIndex(5) @@ -238,7 +238,7 @@ def test_union_sorted(self, unions): res2 = idx2.union(idx1, sort=None) res3 = idx1._int64index.union(idx2, sort=None) tm.assert_index_equal(res2, expected_sorted, exact=True) - tm.assert_index_equal(res3, expected_sorted) + tm.assert_index_equal(res3, expected_sorted, exact="equiv") def test_difference(self): # GH#12034 Cases where we operate against another RangeIndex and may diff --git a/pandas/tests/indexes/test_base.py b/pandas/tests/indexes/test_base.py index ec03d5466d1f0..38dc793bd7114 100644 --- a/pandas/tests/indexes/test_base.py +++ b/pandas/tests/indexes/test_base.py @@ -833,7 +833,8 @@ def test_union_dt_as_obj(self, sort): def test_map_identity_mapping(self, index): # GH 12766 - tm.assert_index_equal(index, index.map(lambda x: x)) + # exact="equiv" bc RangeIndex converts to Int64Index + tm.assert_index_equal(index, index.map(lambda x: x), exact="equiv") def test_map_with_tuples(self): # GH 12766 @@ -871,7 +872,7 @@ def test_map_tseries_indices_return_index(self, attr): def test_map_tseries_indices_accsr_return_index(self): date_index = tm.makeDateIndex(24, freq="h", name="hourly") expected = Index(range(24), name="hourly") - tm.assert_index_equal(expected, date_index.map(lambda x: x.hour)) + tm.assert_index_equal(expected, date_index.map(lambda x: x.hour), exact="equiv") @pytest.mark.parametrize( "mapper", diff --git a/pandas/tests/indexes/test_common.py b/pandas/tests/indexes/test_common.py index a10be99dff076..643dc7901bb72 100644 --- a/pandas/tests/indexes/test_common.py +++ b/pandas/tests/indexes/test_common.py @@ -141,7 +141,8 @@ def test_unique(self, index): expected = index.drop_duplicates() for level in 0, index.name, None: result = index.unique(level=level) - tm.assert_index_equal(result, expected) + # TODO: make exact=True by making RangeIndex.unique return RangeIndex + tm.assert_index_equal(result, expected, exact="equiv") msg = "Too many levels: Index has only 1 level, not 4" with pytest.raises(IndexError, match=msg): diff --git a/pandas/tests/indexes/test_setops.py b/pandas/tests/indexes/test_setops.py index 1be17a9d6116a..0973cef7cfdc1 100644 --- a/pandas/tests/indexes/test_setops.py +++ b/pandas/tests/indexes/test_setops.py @@ -385,8 +385,8 @@ def test_difference_preserves_type_empty(self, index, sort): if not index.is_unique: return result = index.difference(index, sort=sort) - expected = index.drop(index) - tm.assert_index_equal(result, expected) + expected = index[:0] + tm.assert_index_equal(result, expected, exact=True) def test_intersection_difference_match_empty(self, index, sort): # GH#20040 @@ -395,6 +395,6 @@ def test_intersection_difference_match_empty(self, index, sort): # of an index with itself. Test for all types if not index.is_unique: return - inter = index.intersection(index.drop(index)) + inter = index.intersection(index[:0]) diff = index.difference(index, sort=sort) - tm.assert_index_equal(inter, diff) + tm.assert_index_equal(inter, diff, exact=True) diff --git a/pandas/tests/reshape/concat/test_series.py b/pandas/tests/reshape/concat/test_series.py index 20838a418cfea..2d681e792914c 100644 --- a/pandas/tests/reshape/concat/test_series.py +++ b/pandas/tests/reshape/concat/test_series.py @@ -106,9 +106,9 @@ def test_concat_series_axis1_same_names_ignore_index(self): s2 = Series(np.random.randn(len(dates)), index=dates, name="value") result = concat([s1, s2], axis=1, ignore_index=True) - expected = Index([0, 1]) + expected = Index(range(2)) - tm.assert_index_equal(result.columns, expected) + tm.assert_index_equal(result.columns, expected, exact=True) @pytest.mark.parametrize( "s1name,s2name", [(np.int64(190), (43, 0)), (190, (43, 0))] diff --git a/pandas/tests/reshape/merge/test_join.py b/pandas/tests/reshape/merge/test_join.py index 7db92eb55fa0b..113ec0f6becc9 100644 --- a/pandas/tests/reshape/merge/test_join.py +++ b/pandas/tests/reshape/merge/test_join.py @@ -504,7 +504,7 @@ def test_join_sort(self): # smoke test joined = left.join(right, on="key", sort=False) - tm.assert_index_equal(joined.index, Index(list(range(4)))) + tm.assert_index_equal(joined.index, Index(range(4)), exact=True) def test_join_mixed_non_unique_index(self): # GH 12814, unorderable types in py3 with a non-unique index diff --git a/pandas/tests/series/test_constructors.py b/pandas/tests/series/test_constructors.py index debd516da9eec..4623a508fd725 100644 --- a/pandas/tests/series/test_constructors.py +++ b/pandas/tests/series/test_constructors.py @@ -550,7 +550,7 @@ def test_series_ctor_plus_datetimeindex(self): def test_constructor_default_index(self): s = Series([0, 1, 2]) - tm.assert_index_equal(s.index, Index(np.arange(3))) + tm.assert_index_equal(s.index, Index(range(3)), exact=True) @pytest.mark.parametrize( "input", diff --git a/pandas/tests/window/test_pairwise.py b/pandas/tests/window/test_pairwise.py index b39d052a702c0..68782336fd278 100644 --- a/pandas/tests/window/test_pairwise.py +++ b/pandas/tests/window/test_pairwise.py @@ -45,7 +45,10 @@ def test_pairwise_with_self(self, pairwise_frames, pairwise_target_frame, f): # in a non-monotonic way, so compare accordingly result = f(pairwise_frames) tm.assert_index_equal( - result.index.levels[0], pairwise_frames.index, check_names=False + result.index.levels[0], + pairwise_frames.index, + check_names=False, + exact="equiv", ) tm.assert_numpy_array_equal( safe_sort(result.index.levels[1]), @@ -103,7 +106,10 @@ def test_pairwise_with_other( # DataFrame with another DataFrame, pairwise=True result = f(pairwise_frames, pairwise_other_frame) tm.assert_index_equal( - result.index.levels[0], pairwise_frames.index, check_names=False + result.index.levels[0], + pairwise_frames.index, + check_names=False, + exact="equiv", ) tm.assert_numpy_array_equal( safe_sort(result.index.levels[1]), From 28f14a5a15dbe6b400791e25a66d40ab0b61ea5a Mon Sep 17 00:00:00 2001 From: Brock Date: Thu, 26 Nov 2020 11:28:47 -0800 Subject: [PATCH 2/2] revert equivs --- pandas/_testing.py | 6 +----- pandas/tests/arithmetic/test_numeric.py | 2 +- pandas/tests/groupby/test_apply.py | 2 +- pandas/tests/indexes/common.py | 4 ++-- pandas/tests/indexes/ranges/test_constructors.py | 4 ++-- pandas/tests/indexes/ranges/test_join.py | 8 ++++---- pandas/tests/indexes/ranges/test_range.py | 16 ++++++++-------- pandas/tests/indexes/ranges/test_setops.py | 12 ++++++------ pandas/tests/indexes/test_base.py | 5 ++--- pandas/tests/indexes/test_common.py | 3 +-- pandas/tests/window/test_pairwise.py | 10 ++-------- 11 files changed, 30 insertions(+), 42 deletions(-) diff --git a/pandas/_testing.py b/pandas/_testing.py index d582215eab8b0..68371b782aac2 100644 --- a/pandas/_testing.py +++ b/pandas/_testing.py @@ -982,11 +982,7 @@ def assert_categorical_equal( _check_isinstance(left, right, Categorical) if check_category_order: - # TODO: might be able to get exact=True if Categorical(RangeIndex) - # preserved RangeIndex categories - assert_index_equal( - left.categories, right.categories, obj=f"{obj}.categories", exact="equiv" - ) + assert_index_equal(left.categories, right.categories, obj=f"{obj}.categories") assert_numpy_array_equal( left.codes, right.codes, check_dtype=check_dtype, obj=f"{obj}.codes" ) diff --git a/pandas/tests/arithmetic/test_numeric.py b/pandas/tests/arithmetic/test_numeric.py index 10835462b3289..f4f258b559939 100644 --- a/pandas/tests/arithmetic/test_numeric.py +++ b/pandas/tests/arithmetic/test_numeric.py @@ -1185,7 +1185,7 @@ def check_binop(self, ops, scalars, idxs): for scalar in scalars: result = op(idx, scalar) expected = op(Int64Index(idx), scalar) - tm.assert_index_equal(result, expected, exact="equiv") + tm.assert_index_equal(result, expected) def test_binops(self): ops = [ diff --git a/pandas/tests/groupby/test_apply.py b/pandas/tests/groupby/test_apply.py index c5b458c943529..151ec03662335 100644 --- a/pandas/tests/groupby/test_apply.py +++ b/pandas/tests/groupby/test_apply.py @@ -387,7 +387,7 @@ def test_apply_frame_not_as_index_column_name(df): result = grouped.apply(len) expected = grouped.count().rename(columns={"C": np.nan}).drop(columns="D") # TODO: Use assert_frame_equal when column name is not np.nan (GH 36306) - tm.assert_index_equal(result.index, expected.index, exact="equiv") + tm.assert_index_equal(result.index, expected.index) tm.assert_numpy_array_equal(result.values, expected.values) diff --git a/pandas/tests/indexes/common.py b/pandas/tests/indexes/common.py index 9a5bb6fdd23b3..e250d8cf1b326 100644 --- a/pandas/tests/indexes/common.py +++ b/pandas/tests/indexes/common.py @@ -658,7 +658,7 @@ def test_map(self): result = index.map(lambda x: x) # For RangeIndex we convert to Int64Index - tm.assert_index_equal(result, expected, exact="equiv") + tm.assert_index_equal(result, expected) @pytest.mark.parametrize( "mapper", @@ -683,7 +683,7 @@ def test_map_dictlike(self, mapper): result = index.map(identity) # For RangeIndex we convert to Int64Index - tm.assert_index_equal(result, expected, exact="equiv") + tm.assert_index_equal(result, expected) # empty mappable expected = Index([np.nan] * len(index)) diff --git a/pandas/tests/indexes/ranges/test_constructors.py b/pandas/tests/indexes/ranges/test_constructors.py index e1b2fddbce15d..7dd893bd16720 100644 --- a/pandas/tests/indexes/ranges/test_constructors.py +++ b/pandas/tests/indexes/ranges/test_constructors.py @@ -27,7 +27,7 @@ def test_constructor(self, args, kwargs, start, stop, step, name): assert isinstance(result, RangeIndex) assert result.name is name assert result._range == range(start, stop, step) - tm.assert_index_equal(result, expected, exact="equiv") + tm.assert_index_equal(result, expected) def test_constructor_invalid_args(self): msg = "RangeIndex\\(\\.\\.\\.\\) must be called with integers" @@ -146,7 +146,7 @@ def test_constructor_corner(self): arr = np.array([1, 2, 3, 4], dtype=object) index = RangeIndex(1, 5) assert index.values.dtype == np.int64 - tm.assert_index_equal(index, Index(arr), exact="equiv") + tm.assert_index_equal(index, Index(arr)) # non-int raise Exception with pytest.raises(TypeError, match=r"Wrong type \"): diff --git a/pandas/tests/indexes/ranges/test_join.py b/pandas/tests/indexes/ranges/test_join.py index ab7f16098a85b..76013d2b7a387 100644 --- a/pandas/tests/indexes/ranges/test_join.py +++ b/pandas/tests/indexes/ranges/test_join.py @@ -28,7 +28,7 @@ def test_join_outer(self): assert isinstance(res, Int64Index) assert not isinstance(res, RangeIndex) - tm.assert_index_equal(res, eres, exact="equiv") + tm.assert_index_equal(res, eres) tm.assert_numpy_array_equal(lidx, elidx) tm.assert_numpy_array_equal(ridx, eridx) @@ -41,7 +41,7 @@ def test_join_outer(self): assert isinstance(res, Int64Index) assert not isinstance(res, RangeIndex) - tm.assert_index_equal(res, eres, exact="equiv") + tm.assert_index_equal(res, eres) tm.assert_numpy_array_equal(lidx, elidx) tm.assert_numpy_array_equal(ridx, eridx) @@ -63,7 +63,7 @@ def test_join_inner(self): eridx = np.array([9, 7], dtype=np.intp) assert isinstance(res, Int64Index) - tm.assert_index_equal(res, eres, exact="equiv") + tm.assert_index_equal(res, eres) tm.assert_numpy_array_equal(lidx, elidx) tm.assert_numpy_array_equal(ridx, eridx) @@ -73,7 +73,7 @@ def test_join_inner(self): res, lidx, ridx = index.join(other, how="inner", return_indexers=True) assert isinstance(res, RangeIndex) - tm.assert_index_equal(res, eres, exact="equiv") + tm.assert_index_equal(res, eres) tm.assert_numpy_array_equal(lidx, elidx) tm.assert_numpy_array_equal(ridx, eridx) diff --git a/pandas/tests/indexes/ranges/test_range.py b/pandas/tests/indexes/ranges/test_range.py index aab98487f8cc9..8c1272a6e971b 100644 --- a/pandas/tests/indexes/ranges/test_range.py +++ b/pandas/tests/indexes/ranges/test_range.py @@ -394,38 +394,38 @@ def test_slice_specialised(self): # positive slice values index_slice = index[7:10:2] expected = Index(np.array([14, 18]), name="foo") - tm.assert_index_equal(index_slice, expected, exact="equiv") + tm.assert_index_equal(index_slice, expected) # negative slice values index_slice = index[-1:-5:-2] expected = Index(np.array([18, 14]), name="foo") - tm.assert_index_equal(index_slice, expected, exact="equiv") + tm.assert_index_equal(index_slice, expected) # stop overshoot index_slice = index[2:100:4] expected = Index(np.array([4, 12]), name="foo") - tm.assert_index_equal(index_slice, expected, exact="equiv") + tm.assert_index_equal(index_slice, expected) # reverse index_slice = index[::-1] expected = Index(index.values[::-1], name="foo") - tm.assert_index_equal(index_slice, expected, exact="equiv") + tm.assert_index_equal(index_slice, expected) index_slice = index[-8::-1] expected = Index(np.array([4, 2, 0]), name="foo") - tm.assert_index_equal(index_slice, expected, exact="equiv") + tm.assert_index_equal(index_slice, expected) index_slice = index[-40::-1] expected = Index(np.array([], dtype=np.int64), name="foo") - tm.assert_index_equal(index_slice, expected, exact="equiv") + tm.assert_index_equal(index_slice, expected) index_slice = index[40::-1] expected = Index(index.values[40::-1], name="foo") - tm.assert_index_equal(index_slice, expected, exact="equiv") + tm.assert_index_equal(index_slice, expected) index_slice = index[10::-1] expected = Index(index.values[::-1], name="foo") - tm.assert_index_equal(index_slice, expected, exact="equiv") + tm.assert_index_equal(index_slice, expected) @pytest.mark.parametrize("step", set(range(-5, 6)) - {0}) def test_len_specialised(self, step): diff --git a/pandas/tests/indexes/ranges/test_setops.py b/pandas/tests/indexes/ranges/test_setops.py index 99785a96326c1..9c9f5dbdf7e7f 100644 --- a/pandas/tests/indexes/ranges/test_setops.py +++ b/pandas/tests/indexes/ranges/test_setops.py @@ -26,28 +26,28 @@ def test_intersection(self, sort): other = RangeIndex(1, 6) result = index.intersection(other, sort=sort) expected = Index(np.sort(np.intersect1d(index.values, other.values))) - tm.assert_index_equal(result, expected, exact="equiv") + tm.assert_index_equal(result, expected) # intersect with decreasing RangeIndex other = RangeIndex(5, 0, -1) result = index.intersection(other, sort=sort) expected = Index(np.sort(np.intersect1d(index.values, other.values))) - tm.assert_index_equal(result, expected, exact="equiv") + tm.assert_index_equal(result, expected) # reversed (GH 17296) result = other.intersection(index, sort=sort) - tm.assert_index_equal(result, expected, exact="equiv") + tm.assert_index_equal(result, expected) # GH 17296: intersect two decreasing RangeIndexes first = RangeIndex(10, -2, -2) other = RangeIndex(5, -4, -1) expected = first.astype(int).intersection(other.astype(int), sort=sort) result = first.intersection(other, sort=sort).astype(int) - tm.assert_index_equal(result, expected, exact="equiv") + tm.assert_index_equal(result, expected) # reversed result = other.intersection(first, sort=sort).astype(int) - tm.assert_index_equal(result, expected, exact="equiv") + tm.assert_index_equal(result, expected) index = RangeIndex(5) @@ -238,7 +238,7 @@ def test_union_sorted(self, unions): res2 = idx2.union(idx1, sort=None) res3 = idx1._int64index.union(idx2, sort=None) tm.assert_index_equal(res2, expected_sorted, exact=True) - tm.assert_index_equal(res3, expected_sorted, exact="equiv") + tm.assert_index_equal(res3, expected_sorted) def test_difference(self): # GH#12034 Cases where we operate against another RangeIndex and may diff --git a/pandas/tests/indexes/test_base.py b/pandas/tests/indexes/test_base.py index 31fc547ac3d34..ba49c51c9db8e 100644 --- a/pandas/tests/indexes/test_base.py +++ b/pandas/tests/indexes/test_base.py @@ -732,8 +732,7 @@ def test_union_dt_as_obj(self, sort): def test_map_identity_mapping(self, index): # GH 12766 - # exact="equiv" bc RangeIndex converts to Int64Index - tm.assert_index_equal(index, index.map(lambda x: x), exact="equiv") + tm.assert_index_equal(index, index.map(lambda x: x)) def test_map_with_tuples(self): # GH 12766 @@ -771,7 +770,7 @@ def test_map_tseries_indices_return_index(self, attr): def test_map_tseries_indices_accsr_return_index(self): date_index = tm.makeDateIndex(24, freq="h", name="hourly") expected = Index(range(24), name="hourly") - tm.assert_index_equal(expected, date_index.map(lambda x: x.hour), exact="equiv") + tm.assert_index_equal(expected, date_index.map(lambda x: x.hour)) @pytest.mark.parametrize( "mapper", diff --git a/pandas/tests/indexes/test_common.py b/pandas/tests/indexes/test_common.py index 643dc7901bb72..a10be99dff076 100644 --- a/pandas/tests/indexes/test_common.py +++ b/pandas/tests/indexes/test_common.py @@ -141,8 +141,7 @@ def test_unique(self, index): expected = index.drop_duplicates() for level in 0, index.name, None: result = index.unique(level=level) - # TODO: make exact=True by making RangeIndex.unique return RangeIndex - tm.assert_index_equal(result, expected, exact="equiv") + tm.assert_index_equal(result, expected) msg = "Too many levels: Index has only 1 level, not 4" with pytest.raises(IndexError, match=msg): diff --git a/pandas/tests/window/test_pairwise.py b/pandas/tests/window/test_pairwise.py index 68782336fd278..b39d052a702c0 100644 --- a/pandas/tests/window/test_pairwise.py +++ b/pandas/tests/window/test_pairwise.py @@ -45,10 +45,7 @@ def test_pairwise_with_self(self, pairwise_frames, pairwise_target_frame, f): # in a non-monotonic way, so compare accordingly result = f(pairwise_frames) tm.assert_index_equal( - result.index.levels[0], - pairwise_frames.index, - check_names=False, - exact="equiv", + result.index.levels[0], pairwise_frames.index, check_names=False ) tm.assert_numpy_array_equal( safe_sort(result.index.levels[1]), @@ -106,10 +103,7 @@ def test_pairwise_with_other( # DataFrame with another DataFrame, pairwise=True result = f(pairwise_frames, pairwise_other_frame) tm.assert_index_equal( - result.index.levels[0], - pairwise_frames.index, - check_names=False, - exact="equiv", + result.index.levels[0], pairwise_frames.index, check_names=False ) tm.assert_numpy_array_equal( safe_sort(result.index.levels[1]),