Skip to content
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

TST: tighten assert_index_equal calls #38054

Merged
merged 4 commits into from
Nov 26, 2020
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
2 changes: 1 addition & 1 deletion pandas/tests/frame/methods/test_reset_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
10 changes: 5 additions & 5 deletions pandas/tests/frame/test_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -802,14 +802,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)))
Expand Down
3 changes: 3 additions & 0 deletions pandas/tests/indexes/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -656,6 +657,7 @@ def test_map(self):
expected = index

result = index.map(lambda x: x)
# For RangeIndex we convert to Int64Index
tm.assert_index_equal(result, expected)

@pytest.mark.parametrize(
Expand All @@ -680,6 +682,7 @@ def test_map_dictlike(self, mapper):
expected = index

result = index.map(identity)
# For RangeIndex we convert to Int64Index
tm.assert_index_equal(result, expected)

# empty mappable
Expand Down
8 changes: 4 additions & 4 deletions pandas/tests/indexes/test_setops.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
4 changes: 2 additions & 2 deletions pandas/tests/reshape/concat/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))]
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/reshape/merge/test_join.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/series/test_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,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",
Expand Down