Skip to content

Commit ee569b3

Browse files
committed
Review (jreback)
1 parent 19178a7 commit ee569b3

File tree

1 file changed

+25
-27
lines changed

1 file changed

+25
-27
lines changed

pandas/tests/frame/test_alter_axes.py

+25-27
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
class TestDataFrameAlterAxes(TestData):
3030

31-
def test_set_index_manually(self):
31+
def test_set_index_directly(self):
3232
df = self.mixed_frame.copy()
3333
idx = Index(np.arange(len(df))[::-1])
3434

@@ -94,7 +94,7 @@ def test_set_index_append(self, drop, keys):
9494
# A has duplicate values, C does not
9595
@pytest.mark.parametrize('keys', ['A', 'C', ['A', 'B']])
9696
@pytest.mark.parametrize('drop', [True, False])
97-
def test_set_index_append_to_mi(self, drop, keys):
97+
def test_set_index_append_to_multiindex(self, drop, keys):
9898
# append to existing multiindex
9999
df = self.dummy.set_index(['D'], drop=drop, append=True)
100100

@@ -115,66 +115,64 @@ def test_set_index_after_mutation(self):
115115
result = df2.set_index('key')
116116
tm.assert_frame_equal(result, expected)
117117

118-
@pytest.mark.parametrize('container', [Series, Index, np.array, mi])
119118
# also test index name if append=True (name is duplicate here for B)
120-
@pytest.mark.parametrize('append, df_index_name', [(True, None),
119+
@pytest.mark.parametrize('box', [Series, Index, np.array, mi])
120+
@pytest.mark.parametrize('append, index_name', [(True, None),
121121
(True, 'B'), (True, 'test'), (False, None)])
122122
@pytest.mark.parametrize('drop', [True, False])
123-
def test_set_index_pass_single_array(self, drop, append, df_index_name,
124-
container):
123+
def test_set_index_pass_single_array(self, drop, append, index_name, box):
125124
df = self.dummy.copy()
126-
df.index.name = df_index_name
125+
df.index.name = index_name
127126

128-
key = container(df['B'])
127+
key = box(df['B'])
129128
# np.array and list "forget" the name of B
130-
name = [None if container in [np.array, list] else 'B']
129+
name = [None if box in [np.array, list] else 'B']
131130

132131
result = df.set_index(key, drop=drop, append=append)
133132

134133
# only valid column keys are dropped
135134
# since B is always passed as array above, nothing is dropped
136135
expected = df.set_index(['B'], drop=False, append=append)
137-
expected.index.names = [df_index_name] + name if append else name
136+
expected.index.names = [index_name] + name if append else name
138137

139138
tm.assert_frame_equal(result, expected)
140139

141-
@pytest.mark.parametrize('container', [Series, Index, np.array, list, mi])
142140
# also test index name if append=True (name is duplicate here for A & B)
143-
@pytest.mark.parametrize('append, df_index_name',
141+
@pytest.mark.parametrize('box', [Series, Index, np.array, list, mi])
142+
@pytest.mark.parametrize('append, index_name',
144143
[(True, None), (True, 'A'), (True, 'B'),
145144
(True, 'test'), (False, None)])
146145
@pytest.mark.parametrize('drop', [True, False])
147-
def test_set_index_pass_arrays(self, drop, append, df_index_name,
148-
container):
146+
def test_set_index_pass_arrays(self, drop, append, index_name, box):
149147
df = self.dummy.copy()
150-
df.index.name = df_index_name
148+
df.index.name = index_name
151149

152-
keys = ['A', container(df['B'])]
150+
keys = ['A', box(df['B'])]
153151
# np.array and list "forget" the name of B
154-
names = ['A', None if container in [np.array, list] else 'B']
152+
names = ['A', None if box in [np.array, list] else 'B']
155153

156154
result = df.set_index(keys, drop=drop, append=append)
157155

158156
# only valid column keys are dropped
159157
# since B is always passed as array above, only A is dropped, if at all
160158
expected = df.set_index(['A', 'B'], drop=False, append=append)
161159
expected = expected.drop('A', axis=1) if drop else expected
162-
expected.index.names = [df_index_name] + names if append else names
160+
expected.index.names = [index_name] + names if append else names
163161

164162
tm.assert_frame_equal(result, expected)
165163

166-
@pytest.mark.parametrize('elem2', [key, Series, Index, np.array, list, mi])
167-
@pytest.mark.parametrize('elem1', [key, Series, Index, np.array, list, mi])
168164
# also test index name if append=True (name is duplicate here for A)
169-
@pytest.mark.parametrize('append, df_index_name', [(True, None),
165+
@pytest.mark.parametrize('box1', [key, Series, Index, np.array, list, mi])
166+
@pytest.mark.parametrize('box2', [key, Series, Index, np.array, list, mi])
167+
@pytest.mark.parametrize('append, index_name', [(True, None),
170168
(True, 'A'), (True, 'test'), (False, None)])
171169
@pytest.mark.parametrize('drop', [True, False])
172-
def test_set_index_pass_arrays_duplicate(self, drop, append, df_index_name,
173-
elem1, elem2):
170+
def test_set_index_pass_arrays_duplicate(self, drop, append, index_name,
171+
box1, box2):
174172
df = self.dummy.copy()
175-
df.index.name = df_index_name
173+
df.index.name = index_name
176174

177-
keys = [elem1(df['A']), elem2(df['A'])]
175+
keys = [box1(df['A']), box2(df['A'])]
178176

179177
# == gives ambiguous Boolean for Series
180178
if keys[0] is 'A' and keys[1] is 'A':
@@ -186,15 +184,15 @@ def test_set_index_pass_arrays_duplicate(self, drop, append, df_index_name,
186184

187185
# to test against already-tested behavior, we add sequentially,
188186
# hence second append always True; must wrap in list, otherwise
189-
# list-elements will be illegal
187+
# list-box will be illegal
190188
expected = df.set_index([keys[0]], drop=drop, append=append)
191189
expected = expected.set_index([keys[1]], drop=drop, append=True)
192190

193191
tm.assert_frame_equal(result, expected)
194192

195193
@pytest.mark.parametrize('append', [True, False])
196194
@pytest.mark.parametrize('drop', [True, False])
197-
def test_set_index_pass_mi(self, drop, append):
195+
def test_set_index_pass_multiindex(self, drop, append):
198196
df = self.dummy.copy()
199197
keys = MultiIndex.from_arrays([df['A'], df['B']], names=['A', 'B'])
200198

0 commit comments

Comments
 (0)