@@ -166,31 +166,24 @@ def test_is_label_or_level_reference_panel_error(panel):
166
166
def test_check_label_or_level_ambiguity_df (df_ambig , axis ):
167
167
168
168
# Transpose frame if axis == 1
169
- if axis in {1 , ' columns' }:
169
+ if axis in {1 , " columns" }:
170
170
df_ambig = df_ambig .T
171
171
172
- # df_ambig has both an on- axis level and off-axis label named L1
173
- # Therefore L1 is ambiguous
174
- with tm . assert_produces_warning ( FutureWarning ,
175
- clear = True ) as w :
172
+ if axis in { 0 , "index" }:
173
+ msg = "'L1' is both an index level and a column label"
174
+ else :
175
+ msg = "'L1' is both a column level and an index label"
176
176
177
- assert df_ambig ._check_label_or_level_ambiguity ('L1' , axis = axis )
178
- warning_msg = w [0 ].message .args [0 ]
179
- if axis in {0 , 'index' }:
180
- assert warning_msg .startswith ("'L1' is both an index level "
181
- "and a column label" )
182
- else :
183
- assert warning_msg .startswith ("'L1' is both a column level "
184
- "and an index label" )
177
+ # df_ambig has both an on-axis level and off-axis label named L1
178
+ # Therefore, L1 is ambiguous.
179
+ with tm .assert_raises_regex (ValueError , msg ):
180
+ df_ambig ._check_label_or_level_ambiguity ("L1" , axis = axis )
185
181
186
- # df_ambig has an on-axis level named L2 and it is not ambiguous
187
- # No warning should be raised
188
- with tm .assert_produces_warning (None ):
189
- assert not df_ambig ._check_label_or_level_ambiguity ('L2' , axis = axis )
182
+ # df_ambig has an on-axis level named L2,, and it is not ambiguous.
183
+ df_ambig ._check_label_or_level_ambiguity ("L2" , axis = axis )
190
184
191
- # df_ambig has an off-axis label named L3 and it is not ambiguous
192
- with tm .assert_produces_warning (None ):
193
- assert not df_ambig ._is_level_reference ('L3' , axis = axis )
185
+ # df_ambig has an off-axis label named L3, and it is not ambiguous
186
+ assert not df_ambig ._check_label_or_level_ambiguity ("L3" , axis = axis )
194
187
195
188
196
189
# Series
@@ -200,17 +193,15 @@ def test_check_label_or_level_ambiguity_series(df):
200
193
# A series has no columns and therefore references are never ambiguous
201
194
202
195
# Make series with L1 as index
203
- s = df .set_index ('L1' ).L2
204
- with tm .assert_produces_warning (None ):
205
- assert not s ._check_label_or_level_ambiguity ('L1' , axis = 0 )
206
- assert not s ._check_label_or_level_ambiguity ('L2' , axis = 0 )
196
+ s = df .set_index ("L1" ).L2
197
+ s ._check_label_or_level_ambiguity ("L1" , axis = 0 )
198
+ s ._check_label_or_level_ambiguity ("L2" , axis = 0 )
207
199
208
200
# Make series with L1 and L2 as index
209
- s = df .set_index (['L1' , 'L2' ]).L3
210
- with tm .assert_produces_warning (None ):
211
- assert not s ._check_label_or_level_ambiguity ('L1' , axis = 0 )
212
- assert not s ._check_label_or_level_ambiguity ('L2' , axis = 0 )
213
- assert not s ._check_label_or_level_ambiguity ('L3' , axis = 0 )
201
+ s = df .set_index (["L1" , "L2" ]).L3
202
+ s ._check_label_or_level_ambiguity ("L1" , axis = 0 )
203
+ s ._check_label_or_level_ambiguity ("L2" , axis = 0 )
204
+ s ._check_label_or_level_ambiguity ("L3" , axis = 0 )
214
205
215
206
216
207
def test_check_label_or_level_ambiguity_series_axis1_error (df ):
@@ -229,7 +220,7 @@ def test_check_label_or_level_ambiguity_panel_error(panel):
229
220
.format (type = type (panel )))
230
221
231
222
with tm .assert_raises_regex (NotImplementedError , msg ):
232
- panel ._check_label_or_level_ambiguity ('L1' , axis = 0 )
223
+ panel ._check_label_or_level_ambiguity ("L1" , axis = 0 )
233
224
234
225
235
226
# Test _get_label_or_level_values
@@ -241,19 +232,16 @@ def assert_label_values(frame, labels, axis):
241
232
else :
242
233
expected = frame .loc [label ]._values
243
234
244
- result = frame ._get_label_or_level_values (label , axis = axis ,
245
- stacklevel = 2 )
235
+ result = frame ._get_label_or_level_values (label , axis = axis )
246
236
assert array_equivalent (expected , result )
247
237
248
238
249
239
def assert_level_values (frame , levels , axis ):
250
240
for level in levels :
251
- if axis in {0 , ' index' }:
241
+ if axis in {0 , " index" }:
252
242
expected = frame .index .get_level_values (level = level )._values
253
243
else :
254
- expected = (frame .columns
255
- .get_level_values (level = level )
256
- ._values )
244
+ expected = frame .columns .get_level_values (level = level )._values
257
245
258
246
result = frame ._get_label_or_level_values (level , axis = axis )
259
247
assert array_equivalent (expected , result )
@@ -281,18 +269,11 @@ def test_get_label_or_level_values_df_ambig(df_ambig, axis):
281
269
if axis in {1 , 'columns' }:
282
270
df_ambig = df_ambig .T
283
271
284
- # df has both an on-axis level and off-axis label named L1
285
- # Therefore L1 is ambiguous but will default to label
286
- with tm .assert_produces_warning (FutureWarning ):
287
- assert_label_values (df_ambig , ['L1' ], axis = axis )
288
-
289
- # df has an on-axis level named L2 and it is not ambiguous
290
- with tm .assert_produces_warning (None ):
291
- assert_level_values (df_ambig , ['L2' ], axis = axis )
272
+ # df has an on-axis level named L2, and it is not ambiguous.
273
+ assert_level_values (df_ambig , ['L2' ], axis = axis )
292
274
293
- # df has an off-axis label named L3 and it is not ambiguous
294
- with tm .assert_produces_warning (None ):
295
- assert_label_values (df_ambig , ['L3' ], axis = axis )
275
+ # df has an off-axis label named L3, and it is not ambiguous.
276
+ assert_label_values (df_ambig , ['L3' ], axis = axis )
296
277
297
278
298
279
def test_get_label_or_level_values_df_duplabels (df_duplabels , axis ):
0 commit comments