Skip to content

Commit 309af11

Browse files
committed
TST: Flatten TestSetOpsMutation into module-level functions
1 parent 3e9186d commit 309af11

File tree

1 file changed

+55
-52
lines changed

1 file changed

+55
-52
lines changed

pandas/tests/indexes/test_setops.py

Lines changed: 55 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -986,78 +986,81 @@ def test_union_pyarrow_timestamp(self):
986986
tm.assert_index_equal(res, expected)
987987

988988

989-
class TestSetOpsMutation:
990-
def test_intersection_mutation_safety(self):
991-
# GH#63169
992-
index1 = Index([0, 1], name="original")
993-
index2 = Index([0, 1], name="original")
989+
def test_intersection_mutation_safety():
990+
# GH#63169
991+
index1 = Index([0, 1], name="original")
992+
index2 = Index([0, 1], name="original")
994993

995-
result = index1.intersection(index2)
994+
result = index1.intersection(index2)
996995

997-
assert result is not index1
998-
assert result is not index2
996+
assert result is not index1
997+
assert result is not index2
999998

1000-
tm.assert_index_equal(result, index1)
1001-
assert result.name == "original"
999+
tm.assert_index_equal(result, index1)
1000+
assert result.name == "original"
10021001

1003-
index1.name = "changed"
1002+
index1.name = "changed"
10041003

1005-
assert result.name == "original"
1006-
assert index1.name == "changed"
1004+
assert result.name == "original"
1005+
assert index1.name == "changed"
10071006

1008-
def test_union_mutation_safety(self):
1009-
# GH#63169
1010-
index1 = Index([0, 1], name="original")
1011-
index2 = Index([0, 1], name="original")
10121007

1013-
result = index1.union(index2)
1008+
def test_union_mutation_safety():
1009+
# GH#63169
1010+
index1 = Index([0, 1], name="original")
1011+
index2 = Index([0, 1], name="original")
10141012

1015-
assert result is not index1
1016-
assert result is not index2
1013+
result = index1.union(index2)
10171014

1018-
tm.assert_index_equal(result, index1)
1019-
assert result.name == "original"
1015+
assert result is not index1
1016+
assert result is not index2
10201017

1021-
index1.name = "changed"
1018+
tm.assert_index_equal(result, index1)
1019+
assert result.name == "original"
10221020

1023-
assert result.name == "original"
1024-
assert index1.name == "changed"
1021+
index1.name = "changed"
10251022

1026-
def test_union_mutation_safety_other(self):
1027-
# GH#63169
1028-
index1 = Index([0, 1], name="original")
1029-
index2 = Index([0, 1], name="original")
1023+
assert result.name == "original"
1024+
assert index1.name == "changed"
10301025

1031-
result = index1.union(index2)
10321026

1033-
assert result is not index2
1027+
def test_union_mutation_safety_other():
1028+
# GH#63169
1029+
index1 = Index([0, 1], name="original")
1030+
index2 = Index([0, 1], name="original")
10341031

1035-
tm.assert_index_equal(result, index2)
1036-
assert result.name == "original"
1032+
result = index1.union(index2)
10371033

1038-
index2.name = "changed"
1034+
assert result is not index2
10391035

1040-
assert result.name == "original"
1041-
assert index2.name == "changed"
1036+
tm.assert_index_equal(result, index2)
1037+
assert result.name == "original"
10421038

1043-
def test_multiindex_intersection_mutation_safety(self):
1044-
# GH#63169
1045-
mi1 = MultiIndex.from_tuples([("a", 1), ("b", 2)], names=["x", "y"])
1046-
mi2 = MultiIndex.from_tuples([("a", 1), ("b", 2)], names=["x", "y"])
1039+
index2.name = "changed"
10471040

1048-
result = mi1.intersection(mi2)
1049-
assert result is not mi1
1041+
assert result.name == "original"
1042+
assert index2.name == "changed"
10501043

1051-
mi1.names = ["changed1", "changed2"]
1052-
assert result.names == ["x", "y"]
10531044

1054-
def test_multiindex_union_mutation_safety(self):
1055-
# GH#63169
1056-
mi1 = MultiIndex.from_tuples([("a", 1), ("b", 2)], names=["x", "y"])
1057-
mi2 = MultiIndex.from_tuples([("a", 1), ("b", 2)], names=["x", "y"])
1045+
def test_multiindex_intersection_mutation_safety():
1046+
# GH#63169
1047+
mi1 = MultiIndex.from_tuples([("a", 1), ("b", 2)], names=["x", "y"])
1048+
mi2 = MultiIndex.from_tuples([("a", 1), ("b", 2)], names=["x", "y"])
10581049

1059-
result = mi1.union(mi2)
1060-
assert result is not mi1
1050+
result = mi1.intersection(mi2)
1051+
assert result is not mi1
10611052

1062-
mi1.names = ["changed1", "changed2"]
1063-
assert result.names == ["x", "y"]
1053+
mi1.names = ["changed1", "changed2"]
1054+
assert result.names == ["x", "y"]
1055+
1056+
1057+
def test_multiindex_union_mutation_safety():
1058+
# GH#63169
1059+
mi1 = MultiIndex.from_tuples([("a", 1), ("b", 2)], names=["x", "y"])
1060+
mi2 = MultiIndex.from_tuples([("a", 1), ("b", 2)], names=["x", "y"])
1061+
1062+
result = mi1.union(mi2)
1063+
assert result is not mi1
1064+
1065+
mi1.names = ["changed1", "changed2"]
1066+
assert result.names == ["x", "y"]

0 commit comments

Comments
 (0)