3
3
import re
4
4
5
5
import numpy as np
6
- import pytest
7
- from pandas ._libs .tslib import Timestamp
8
-
9
6
import pandas as pd
10
7
import pandas .util .testing as tm
8
+ import pytest
11
9
from pandas import Index , MultiIndex , date_range
10
+ from pandas ._libs .tslib import Timestamp
12
11
from pandas .compat import lrange , range
13
12
from pandas .core .dtypes .cast import construct_1d_object_array_from_listlike
14
13
@@ -24,7 +23,7 @@ def test_constructor_single_level():
24
23
25
24
def test_constructor_no_levels ():
26
25
tm .assert_raises_regex (ValueError , "non-zero number "
27
- "of levels/labels" ,
26
+ "of levels/labels" ,
28
27
MultiIndex , levels = [], labels = [])
29
28
both_re = re .compile ('Must pass both levels and labels' )
30
29
with tm .assert_raises_regex (TypeError , both_re ):
@@ -57,7 +56,7 @@ def test_constructor_mismatched_label_levels(idx):
57
56
labels = [np .array ([1 ]), np .array ([2 ]), np .array ([3 ])]
58
57
levels = ["a" ]
59
58
tm .assert_raises_regex (ValueError , "Length of levels and labels "
60
- "must be the same" , MultiIndex ,
59
+ "must be the same" , MultiIndex ,
61
60
levels = levels , labels = labels )
62
61
length_error = re .compile ('>= length of level' )
63
62
label_error = re .compile (r'Unequal label lengths: \[4, 2\]' )
@@ -260,13 +259,13 @@ def test_from_arrays_invalid_input(invalid_array):
260
259
def test_from_arrays_different_lengths (idx1 , idx2 ):
261
260
# see gh-13599
262
261
tm .assert_raises_regex (ValueError , '^all arrays must '
263
- 'be same length$' ,
262
+ 'be same length$' ,
264
263
MultiIndex .from_arrays , [idx1 , idx2 ])
265
264
266
265
267
266
def test_from_tuples ():
268
267
tm .assert_raises_regex (TypeError , 'Cannot infer number of levels '
269
- 'from empty list' ,
268
+ 'from empty list' ,
270
269
MultiIndex .from_tuples , [])
271
270
272
271
expected = MultiIndex (levels = [[1 , 3 ], [2 , 4 ]],
@@ -391,6 +390,7 @@ def test_from_product_index_series_categorical(ordered, f):
391
390
392
391
393
392
def test_from_product ():
393
+
394
394
first = ['foo' , 'bar' , 'buz' ]
395
395
second = ['a' , 'b' , 'c' ]
396
396
names = ['first' , 'second' ]
@@ -425,6 +425,7 @@ def test_from_product_iterator():
425
425
426
426
427
427
def test_create_index_existing_name (idx ):
428
+
428
429
# GH11193, when an existing index is passed, and a new name is not
429
430
# specified, the new index should inherit the previous object name
430
431
index = idx
@@ -463,9 +464,8 @@ def test_tuples_with_name_string():
463
464
with pytest .raises (ValueError ):
464
465
pd .Index (li , name = 'a' )
465
466
466
-
467
467
def test_from_tuples_with_tuple_label ():
468
- # test for fix of issue # 15457, where the following raised a TypeError
468
+ # GH 15457
469
469
expected = pd .DataFrame ([[2 , 1 , 2 ], [4 , (1 , 2 ), 3 ]], columns = ['a' , 'b' , 'c' ]).set_index (['a' , 'b' ])
470
470
idx = pd .MultiIndex .from_tuples ([(2 , 1 ), (4 , (1 , 2 ))], names = ('a' , 'b' ))
471
471
result = pd .DataFrame ([2 , 3 ], columns = ['c' ], index = idx )
0 commit comments