@@ -118,6 +118,18 @@ def test_ndarray_compat_properties(self):
118
118
idx .nbytes
119
119
idx .values .nbytes
120
120
121
+ def test_repr_roundtrip (self ):
122
+
123
+ idx = self .create_index ()
124
+ tm .assert_index_equal (eval (repr (idx )),idx )
125
+
126
+ def test_str (self ):
127
+
128
+ # test the string repr
129
+ idx = self .create_index ()
130
+ idx .name = 'foo'
131
+ self .assertTrue ("name=u'foo'" in str (idx ))
132
+ self .assertTrue (idx .__class__ .__name__ in str (idx ))
121
133
122
134
class TestIndex (Base , tm .TestCase ):
123
135
_holder = Index
@@ -2052,6 +2064,26 @@ def test_slice_keep_name(self):
2052
2064
2053
2065
class DatetimeLike (Base ):
2054
2066
2067
+ def test_repr_roundtrip (self ):
2068
+ raise nose .SkipTest ("Short reprs are not supported repr for Datetimelike indexes" )
2069
+
2070
+ def test_str (self ):
2071
+
2072
+ # test the string repr
2073
+ idx = self .create_index ()
2074
+ idx .name = 'foo'
2075
+ self .assertTrue ("length=%s" % len (idx ) in str (idx ))
2076
+ self .assertTrue ("name=u'foo'" in str (idx ))
2077
+ self .assertTrue (idx .__class__ .__name__ in str (idx ))
2078
+
2079
+ if hasattr (idx ,'tz' ):
2080
+ if idx .tz is not None :
2081
+ self .assertTrue ("tz='%s'" % idx .tz in str (idx ))
2082
+ else :
2083
+ self .assertTrue ("tz=None" in str (idx ))
2084
+ if hasattr (idx ,'freq' ):
2085
+ self .assertTrue ("freq='%s'" % idx .freqstr in str (idx ))
2086
+
2055
2087
def test_view (self ):
2056
2088
2057
2089
i = self .create_index ()
@@ -3951,8 +3983,9 @@ def test_repr_with_unicode_data(self):
3951
3983
index = pd .DataFrame (d ).set_index (["a" , "b" ]).index
3952
3984
self .assertFalse ("\\ u" in repr (index )) # we don't want unicode-escaped
3953
3985
3954
- def test_repr_roundtrip (self ):
3955
- tm .assert_index_equal (eval (repr (self .index )), self .index )
3986
+ def test_str (self ):
3987
+ # tested elsewhere
3988
+ pass
3956
3989
3957
3990
def test_unicode_string_with_unicode (self ):
3958
3991
d = {"a" : [u ("\u05d0 " ), 2 , 3 ], "b" : [4 , 5 , 6 ], "c" : [7 , 8 , 9 ]}
0 commit comments