@@ -180,7 +180,7 @@ def test_difference(idx, sort):
180
180
181
181
# name from non-empty array
182
182
result = first .difference ([("foo" , "one" )], sort = sort )
183
- expected = pd . MultiIndex .from_tuples (
183
+ expected = MultiIndex .from_tuples (
184
184
[("bar" , "one" ), ("baz" , "two" ), ("foo" , "two" ), ("qux" , "one" ), ("qux" , "two" )]
185
185
)
186
186
expected .names = first .names
@@ -193,7 +193,7 @@ def test_difference(idx, sort):
193
193
194
194
def test_difference_sort_special ():
195
195
# GH-24959
196
- idx = pd . MultiIndex .from_product ([[1 , 0 ], ["a" , "b" ]])
196
+ idx = MultiIndex .from_product ([[1 , 0 ], ["a" , "b" ]])
197
197
# sort=None, the default
198
198
result = idx .difference ([])
199
199
tm .assert_index_equal (result , idx )
@@ -202,17 +202,17 @@ def test_difference_sort_special():
202
202
@pytest .mark .xfail (reason = "Not implemented." )
203
203
def test_difference_sort_special_true ():
204
204
# TODO decide on True behaviour
205
- idx = pd . MultiIndex .from_product ([[1 , 0 ], ["a" , "b" ]])
205
+ idx = MultiIndex .from_product ([[1 , 0 ], ["a" , "b" ]])
206
206
result = idx .difference ([], sort = True )
207
- expected = pd . MultiIndex .from_product ([[0 , 1 ], ["a" , "b" ]])
207
+ expected = MultiIndex .from_product ([[0 , 1 ], ["a" , "b" ]])
208
208
tm .assert_index_equal (result , expected )
209
209
210
210
211
211
def test_difference_sort_incomparable ():
212
212
# GH-24959
213
- idx = pd . MultiIndex .from_product ([[1 , pd .Timestamp ("2000" ), 2 ], ["a" , "b" ]])
213
+ idx = MultiIndex .from_product ([[1 , pd .Timestamp ("2000" ), 2 ], ["a" , "b" ]])
214
214
215
- other = pd . MultiIndex .from_product ([[3 , pd .Timestamp ("2000" ), 4 ], ["c" , "d" ]])
215
+ other = MultiIndex .from_product ([[3 , pd .Timestamp ("2000" ), 4 ], ["c" , "d" ]])
216
216
# sort=None, the default
217
217
# MultiIndex.difference deviates here from other difference
218
218
# implementations in not catching the TypeError
@@ -226,8 +226,8 @@ def test_difference_sort_incomparable():
226
226
227
227
228
228
def test_difference_sort_incomparable_true ():
229
- idx = pd . MultiIndex .from_product ([[1 , pd .Timestamp ("2000" ), 2 ], ["a" , "b" ]])
230
- other = pd . MultiIndex .from_product ([[3 , pd .Timestamp ("2000" ), 4 ], ["c" , "d" ]])
229
+ idx = MultiIndex .from_product ([[1 , pd .Timestamp ("2000" ), 2 ], ["a" , "b" ]])
230
+ other = MultiIndex .from_product ([[3 , pd .Timestamp ("2000" ), 4 ], ["c" , "d" ]])
231
231
232
232
msg = "The 'sort' keyword only takes the values of None or False; True was passed."
233
233
with pytest .raises (ValueError , match = msg ):
@@ -332,23 +332,23 @@ def test_intersection_non_object(idx, sort):
332
332
333
333
def test_intersect_equal_sort ():
334
334
# GH-24959
335
- idx = pd . MultiIndex .from_product ([[1 , 0 ], ["a" , "b" ]])
335
+ idx = MultiIndex .from_product ([[1 , 0 ], ["a" , "b" ]])
336
336
tm .assert_index_equal (idx .intersection (idx , sort = False ), idx )
337
337
tm .assert_index_equal (idx .intersection (idx , sort = None ), idx )
338
338
339
339
340
340
@pytest .mark .xfail (reason = "Not implemented." )
341
341
def test_intersect_equal_sort_true ():
342
342
# TODO decide on True behaviour
343
- idx = pd . MultiIndex .from_product ([[1 , 0 ], ["a" , "b" ]])
344
- sorted_ = pd . MultiIndex .from_product ([[0 , 1 ], ["a" , "b" ]])
343
+ idx = MultiIndex .from_product ([[1 , 0 ], ["a" , "b" ]])
344
+ sorted_ = MultiIndex .from_product ([[0 , 1 ], ["a" , "b" ]])
345
345
tm .assert_index_equal (idx .intersection (idx , sort = True ), sorted_ )
346
346
347
347
348
348
@pytest .mark .parametrize ("slice_" , [slice (None ), slice (0 )])
349
349
def test_union_sort_other_empty (slice_ ):
350
350
# https://github.com/pandas-dev/pandas/issues/24959
351
- idx = pd . MultiIndex .from_product ([[1 , 0 ], ["a" , "b" ]])
351
+ idx = MultiIndex .from_product ([[1 , 0 ], ["a" , "b" ]])
352
352
353
353
# default, sort=None
354
354
other = idx [slice_ ]
@@ -364,16 +364,16 @@ def test_union_sort_other_empty(slice_):
364
364
def test_union_sort_other_empty_sort (slice_ ):
365
365
# TODO decide on True behaviour
366
366
# # sort=True
367
- idx = pd . MultiIndex .from_product ([[1 , 0 ], ["a" , "b" ]])
367
+ idx = MultiIndex .from_product ([[1 , 0 ], ["a" , "b" ]])
368
368
other = idx [:0 ]
369
369
result = idx .union (other , sort = True )
370
- expected = pd . MultiIndex .from_product ([[0 , 1 ], ["a" , "b" ]])
370
+ expected = MultiIndex .from_product ([[0 , 1 ], ["a" , "b" ]])
371
371
tm .assert_index_equal (result , expected )
372
372
373
373
374
374
def test_union_sort_other_incomparable ():
375
375
# https://github.com/pandas-dev/pandas/issues/24959
376
- idx = pd . MultiIndex .from_product ([[1 , pd .Timestamp ("2000" )], ["a" , "b" ]])
376
+ idx = MultiIndex .from_product ([[1 , pd .Timestamp ("2000" )], ["a" , "b" ]])
377
377
378
378
# default, sort=None
379
379
with tm .assert_produces_warning (RuntimeWarning ):
@@ -389,14 +389,14 @@ def test_union_sort_other_incomparable():
389
389
def test_union_sort_other_incomparable_sort ():
390
390
# TODO decide on True behaviour
391
391
# # sort=True
392
- idx = pd . MultiIndex .from_product ([[1 , pd .Timestamp ("2000" )], ["a" , "b" ]])
392
+ idx = MultiIndex .from_product ([[1 , pd .Timestamp ("2000" )], ["a" , "b" ]])
393
393
with pytest .raises (TypeError , match = "Cannot compare" ):
394
394
idx .union (idx [:1 ], sort = True )
395
395
396
396
397
397
def test_union_non_object_dtype_raises ():
398
398
# GH#32646 raise NotImplementedError instead of less-informative error
399
- mi = pd . MultiIndex .from_product ([["a" , "b" ], [1 , 2 ]])
399
+ mi = MultiIndex .from_product ([["a" , "b" ], [1 , 2 ]])
400
400
401
401
idx = mi .levels [1 ]
402
402
@@ -418,8 +418,8 @@ def test_union_empty_self_different_names():
418
418
"method" , ["union" , "intersection" , "difference" , "symmetric_difference" ]
419
419
)
420
420
def test_setops_disallow_true (method ):
421
- idx1 = pd . MultiIndex .from_product ([["a" , "b" ], [1 , 2 ]])
422
- idx2 = pd . MultiIndex .from_product ([["b" , "c" ], [1 , 2 ]])
421
+ idx1 = MultiIndex .from_product ([["a" , "b" ], [1 , 2 ]])
422
+ idx2 = MultiIndex .from_product ([["b" , "c" ], [1 , 2 ]])
423
423
424
424
with pytest .raises (ValueError , match = "The 'sort' keyword only takes" ):
425
425
getattr (idx1 , method )(idx2 , sort = True )
@@ -465,8 +465,8 @@ def test_intersect_with_duplicates(tuples, exp_tuples):
465
465
)
466
466
def test_maybe_match_names (data , names , expected ):
467
467
# GH#38323
468
- mi = pd . MultiIndex .from_tuples ([], names = ["a" , "b" ])
469
- mi2 = pd . MultiIndex .from_tuples ([data ], names = names )
468
+ mi = MultiIndex .from_tuples ([], names = ["a" , "b" ])
469
+ mi2 = MultiIndex .from_tuples ([data ], names = names )
470
470
result = mi ._maybe_match_names (mi2 )
471
471
assert result == expected
472
472
0 commit comments