@@ -176,7 +176,7 @@ def test_difference(idx, sort):
176
176
177
177
# name from non-empty array
178
178
result = first .difference ([("foo" , "one" )], sort = sort )
179
- expected = pd . MultiIndex .from_tuples (
179
+ expected = MultiIndex .from_tuples (
180
180
[("bar" , "one" ), ("baz" , "two" ), ("foo" , "two" ), ("qux" , "one" ), ("qux" , "two" )]
181
181
)
182
182
expected .names = first .names
@@ -189,7 +189,7 @@ def test_difference(idx, sort):
189
189
190
190
def test_difference_sort_special ():
191
191
# GH-24959
192
- idx = pd . MultiIndex .from_product ([[1 , 0 ], ["a" , "b" ]])
192
+ idx = MultiIndex .from_product ([[1 , 0 ], ["a" , "b" ]])
193
193
# sort=None, the default
194
194
result = idx .difference ([])
195
195
tm .assert_index_equal (result , idx )
@@ -198,17 +198,17 @@ def test_difference_sort_special():
198
198
@pytest .mark .xfail (reason = "Not implemented." )
199
199
def test_difference_sort_special_true ():
200
200
# TODO decide on True behaviour
201
- idx = pd . MultiIndex .from_product ([[1 , 0 ], ["a" , "b" ]])
201
+ idx = MultiIndex .from_product ([[1 , 0 ], ["a" , "b" ]])
202
202
result = idx .difference ([], sort = True )
203
- expected = pd . MultiIndex .from_product ([[0 , 1 ], ["a" , "b" ]])
203
+ expected = MultiIndex .from_product ([[0 , 1 ], ["a" , "b" ]])
204
204
tm .assert_index_equal (result , expected )
205
205
206
206
207
207
def test_difference_sort_incomparable ():
208
208
# GH-24959
209
- idx = pd . MultiIndex .from_product ([[1 , pd .Timestamp ("2000" ), 2 ], ["a" , "b" ]])
209
+ idx = MultiIndex .from_product ([[1 , pd .Timestamp ("2000" ), 2 ], ["a" , "b" ]])
210
210
211
- other = pd . MultiIndex .from_product ([[3 , pd .Timestamp ("2000" ), 4 ], ["c" , "d" ]])
211
+ other = MultiIndex .from_product ([[3 , pd .Timestamp ("2000" ), 4 ], ["c" , "d" ]])
212
212
# sort=None, the default
213
213
# MultiIndex.difference deviates here from other difference
214
214
# implementations in not catching the TypeError
@@ -222,8 +222,8 @@ def test_difference_sort_incomparable():
222
222
223
223
224
224
def test_difference_sort_incomparable_true ():
225
- idx = pd . MultiIndex .from_product ([[1 , pd .Timestamp ("2000" ), 2 ], ["a" , "b" ]])
226
- other = pd . MultiIndex .from_product ([[3 , pd .Timestamp ("2000" ), 4 ], ["c" , "d" ]])
225
+ idx = MultiIndex .from_product ([[1 , pd .Timestamp ("2000" ), 2 ], ["a" , "b" ]])
226
+ other = MultiIndex .from_product ([[3 , pd .Timestamp ("2000" ), 4 ], ["c" , "d" ]])
227
227
228
228
msg = "The 'sort' keyword only takes the values of None or False; True was passed."
229
229
with pytest .raises (ValueError , match = msg ):
@@ -328,23 +328,23 @@ def test_intersection_non_object(idx, sort):
328
328
329
329
def test_intersect_equal_sort ():
330
330
# GH-24959
331
- idx = pd . MultiIndex .from_product ([[1 , 0 ], ["a" , "b" ]])
331
+ idx = MultiIndex .from_product ([[1 , 0 ], ["a" , "b" ]])
332
332
tm .assert_index_equal (idx .intersection (idx , sort = False ), idx )
333
333
tm .assert_index_equal (idx .intersection (idx , sort = None ), idx )
334
334
335
335
336
336
@pytest .mark .xfail (reason = "Not implemented." )
337
337
def test_intersect_equal_sort_true ():
338
338
# TODO decide on True behaviour
339
- idx = pd . MultiIndex .from_product ([[1 , 0 ], ["a" , "b" ]])
340
- sorted_ = pd . MultiIndex .from_product ([[0 , 1 ], ["a" , "b" ]])
339
+ idx = MultiIndex .from_product ([[1 , 0 ], ["a" , "b" ]])
340
+ sorted_ = MultiIndex .from_product ([[0 , 1 ], ["a" , "b" ]])
341
341
tm .assert_index_equal (idx .intersection (idx , sort = True ), sorted_ )
342
342
343
343
344
344
@pytest .mark .parametrize ("slice_" , [slice (None ), slice (0 )])
345
345
def test_union_sort_other_empty (slice_ ):
346
346
# https://github.com/pandas-dev/pandas/issues/24959
347
- idx = pd . MultiIndex .from_product ([[1 , 0 ], ["a" , "b" ]])
347
+ idx = MultiIndex .from_product ([[1 , 0 ], ["a" , "b" ]])
348
348
349
349
# default, sort=None
350
350
other = idx [slice_ ]
@@ -360,16 +360,16 @@ def test_union_sort_other_empty(slice_):
360
360
def test_union_sort_other_empty_sort (slice_ ):
361
361
# TODO decide on True behaviour
362
362
# # sort=True
363
- idx = pd . MultiIndex .from_product ([[1 , 0 ], ["a" , "b" ]])
363
+ idx = MultiIndex .from_product ([[1 , 0 ], ["a" , "b" ]])
364
364
other = idx [:0 ]
365
365
result = idx .union (other , sort = True )
366
- expected = pd . MultiIndex .from_product ([[0 , 1 ], ["a" , "b" ]])
366
+ expected = MultiIndex .from_product ([[0 , 1 ], ["a" , "b" ]])
367
367
tm .assert_index_equal (result , expected )
368
368
369
369
370
370
def test_union_sort_other_incomparable ():
371
371
# https://github.com/pandas-dev/pandas/issues/24959
372
- idx = pd . MultiIndex .from_product ([[1 , pd .Timestamp ("2000" )], ["a" , "b" ]])
372
+ idx = MultiIndex .from_product ([[1 , pd .Timestamp ("2000" )], ["a" , "b" ]])
373
373
374
374
# default, sort=None
375
375
with tm .assert_produces_warning (RuntimeWarning ):
@@ -385,14 +385,14 @@ def test_union_sort_other_incomparable():
385
385
def test_union_sort_other_incomparable_sort ():
386
386
# TODO decide on True behaviour
387
387
# # sort=True
388
- idx = pd . MultiIndex .from_product ([[1 , pd .Timestamp ("2000" )], ["a" , "b" ]])
388
+ idx = MultiIndex .from_product ([[1 , pd .Timestamp ("2000" )], ["a" , "b" ]])
389
389
with pytest .raises (TypeError , match = "Cannot compare" ):
390
390
idx .union (idx [:1 ], sort = True )
391
391
392
392
393
393
def test_union_non_object_dtype_raises ():
394
394
# GH#32646 raise NotImplementedError instead of less-informative error
395
- mi = pd . MultiIndex .from_product ([["a" , "b" ], [1 , 2 ]])
395
+ mi = MultiIndex .from_product ([["a" , "b" ], [1 , 2 ]])
396
396
397
397
idx = mi .levels [1 ]
398
398
@@ -414,8 +414,8 @@ def test_union_empty_self_different_names():
414
414
"method" , ["union" , "intersection" , "difference" , "symmetric_difference" ]
415
415
)
416
416
def test_setops_disallow_true (method ):
417
- idx1 = pd . MultiIndex .from_product ([["a" , "b" ], [1 , 2 ]])
418
- idx2 = pd . MultiIndex .from_product ([["b" , "c" ], [1 , 2 ]])
417
+ idx1 = MultiIndex .from_product ([["a" , "b" ], [1 , 2 ]])
418
+ idx2 = MultiIndex .from_product ([["b" , "c" ], [1 , 2 ]])
419
419
420
420
with pytest .raises (ValueError , match = "The 'sort' keyword only takes" ):
421
421
getattr (idx1 , method )(idx2 , sort = True )
@@ -461,8 +461,8 @@ def test_intersect_with_duplicates(tuples, exp_tuples):
461
461
)
462
462
def test_maybe_match_names (data , names , expected ):
463
463
# GH#38323
464
- mi = pd . MultiIndex .from_tuples ([], names = ["a" , "b" ])
465
- mi2 = pd . MultiIndex .from_tuples ([data ], names = names )
464
+ mi = MultiIndex .from_tuples ([], names = ["a" , "b" ])
465
+ mi2 = MultiIndex .from_tuples ([data ], names = names )
466
466
result = mi ._maybe_match_names (mi2 )
467
467
assert result == expected
468
468
0 commit comments