@@ -36,21 +36,23 @@ class TestIndex(unittest.TestCase):
36
36
_multiprocess_can_split_ = True
37
37
38
38
def setUp (self ):
39
- self .unicodeIndex = tm .makeUnicodeIndex (100 )
40
- self .strIndex = tm .makeStringIndex (100 )
41
- self .dateIndex = tm .makeDateIndex (100 )
42
- self .intIndex = tm .makeIntIndex (100 )
43
- self .floatIndex = tm .makeFloatIndex (100 )
44
- self .empty = Index ([])
45
- self .tuples = Index (lzip (['foo' , 'bar' , 'baz' ], [1 , 2 , 3 ]))
39
+ self .indices = dict (
40
+ unicodeIndex = tm .makeUnicodeIndex (100 ),
41
+ strIndex = tm .makeStringIndex (100 ),
42
+ dateIndex = tm .makeDateIndex (100 ),
43
+ intIndex = tm .makeIntIndex (100 ),
44
+ floatIndex = tm .makeFloatIndex (100 ),
45
+ empty = Index ([]),
46
+ tuples = Index (lzip (['foo' , 'bar' , 'baz' ], [1 , 2 , 3 ])),
47
+ )
48
+ for name , ind in self .indices .items ():
49
+ setattr (self , name , ind )
46
50
47
51
def test_wrong_number_names (self ):
48
52
def testit (ind ):
49
53
ind .names = ["apple" , "banana" , "carrot" ]
50
54
51
- indices = (self .dateIndex , self .unicodeIndex , self .strIndex ,
52
- self .intIndex , self .floatIndex , self .empty , self .tuples )
53
- for ind in indices :
55
+ for ind in self .indices .values ():
54
56
assertRaisesRegexp (ValueError , "^Length" , testit , ind )
55
57
56
58
def test_set_name_methods (self ):
@@ -700,6 +702,10 @@ def test_hash_error(self):
700
702
type (self .float ).__name__ ):
701
703
hash (self .float )
702
704
705
+ def test_repr_roundtrip (self ):
706
+ for ind in (self .mixed , self .float ):
707
+ tm .assert_index_equal (eval (repr (ind )), ind )
708
+
703
709
def check_is_index (self , i ):
704
710
self .assert_ (isinstance (i , Index ) and not isinstance (i , Float64Index ))
705
711
@@ -1167,6 +1173,9 @@ def test_repr_summary(self):
1167
1173
self .assertTrue (len (r ) < 100 )
1168
1174
self .assertTrue ("..." in r )
1169
1175
1176
+ def test_repr_roundtrip (self ):
1177
+ tm .assert_index_equal (eval (repr (self .index )), self .index )
1178
+
1170
1179
def test_unicode_string_with_unicode (self ):
1171
1180
idx = Index (lrange (1000 ))
1172
1181
@@ -2291,6 +2300,9 @@ def test_repr_with_unicode_data(self):
2291
2300
index = pd .DataFrame (d ).set_index (["a" , "b" ]).index
2292
2301
self .assertFalse ("\\ u" in repr (index )) # we don't want unicode-escaped
2293
2302
2303
+ def test_repr_roundtrip (self ):
2304
+ tm .assert_index_equal (eval (repr (self .index )), self .index )
2305
+
2294
2306
def test_unicode_string_with_unicode (self ):
2295
2307
d = {"a" : [u ("\u05d0 " ), 2 , 3 ], "b" : [4 , 5 , 6 ], "c" : [7 , 8 , 9 ]}
2296
2308
idx = pd .DataFrame (d ).set_index (["a" , "b" ]).index
0 commit comments