@@ -413,21 +413,33 @@ def __unicode__(self):
413
413
klass = self .__class__ .__name__
414
414
data = self ._format_data ()
415
415
attrs = self ._format_attrs ()
416
- max_seq_items = get_option ('display.max_seq_items' )
417
- if len (self ) > max_seq_items :
418
- space = "\n %s" % (' ' * (len (klass ) + 1 ))
419
- else :
420
- space = " "
416
+ space = self ._format_space ()
421
417
422
418
prepr = (u (",%s" ) % space ).join ([u ("%s=%s" ) % (k , v )
423
419
for k , v in attrs ])
424
- res = u ("%s(%s,%s%s)" ) % (klass ,
425
- data ,
426
- space ,
427
- prepr )
420
+
421
+ # no data provided, just attributes
422
+ if data is None :
423
+ data = ''
424
+ else :
425
+ data = "%s,%s" % (data , space )
426
+
427
+ res = u ("%s(%s%s)" ) % (klass ,
428
+ data ,
429
+ prepr )
428
430
429
431
return res
430
432
433
+ def _format_space (self ):
434
+
435
+ # using space here controls if the attributes
436
+ # are line separated or not (the default)
437
+
438
+ #max_seq_items = get_option('display.max_seq_items')
439
+ #if len(self) > max_seq_items:
440
+ # space = "\n%s" % (' ' * (len(klass) + 1))
441
+ return " "
442
+
431
443
@property
432
444
def _formatter_func (self ):
433
445
"""
@@ -439,7 +451,6 @@ def _format_data(self):
439
451
"""
440
452
Return the formatted data as a unicode string
441
453
"""
442
-
443
454
max_seq_items = get_option ('display.max_seq_items' )
444
455
formatter = self ._formatter_func
445
456
n = len (self )
@@ -3280,40 +3291,24 @@ def nbytes(self):
3280
3291
names_nbytes = sum (( getsizeof (i ) for i in self .names ))
3281
3292
return level_nbytes + label_nbytes + names_nbytes
3282
3293
3283
- def __repr__ (self ):
3284
- encoding = get_option ('display.encoding' )
3294
+ def _format_attrs (self ):
3295
+ """
3296
+ Return a list of tuples of the (attr,formatted_value)
3297
+ """
3285
3298
attrs = [('levels' , default_pprint (self .levels )),
3286
3299
('labels' , default_pprint (self .labels ))]
3287
3300
if not all (name is None for name in self .names ):
3288
3301
attrs .append (('names' , default_pprint (self .names )))
3289
3302
if self .sortorder is not None :
3290
3303
attrs .append (('sortorder' , default_pprint (self .sortorder )))
3304
+ return attrs
3291
3305
3292
- space = ' ' * (len (self .__class__ .__name__ ) + 1 )
3293
- prepr = (u (",\n %s" ) % space ).join ([u ("%s=%s" ) % (k , v )
3294
- for k , v in attrs ])
3295
- res = u ("%s(%s)" ) % (self .__class__ .__name__ , prepr )
3306
+ def _format_space (self ):
3307
+ return "\n %s" % (' ' * (len (self .__class__ .__name__ ) + 1 ))
3296
3308
3297
- if not compat .PY3 :
3298
- # needs to be str in Python 2
3299
- res = res .encode (encoding )
3300
- return res
3301
-
3302
- def __unicode__ (self ):
3303
- """
3304
- Return a string representation for a particular Index
3305
-
3306
- Invoked by unicode(df) in py2 only. Yields a Unicode String in both
3307
- py2/py3.
3308
- """
3309
- rows = self .format (names = True )
3310
- max_rows = get_option ('display.max_rows' )
3311
- if len (rows ) > max_rows :
3312
- spaces = (len (rows [0 ]) - 3 ) // 2
3313
- centered = ' ' * spaces
3314
- half = max_rows // 2
3315
- rows = rows [:half ] + [centered + '...' + centered ] + rows [- half :]
3316
- return "\n " .join (rows )
3309
+ def _format_data (self ):
3310
+ # we are formatting thru the attributes
3311
+ return None
3317
3312
3318
3313
def __len__ (self ):
3319
3314
return len (self .labels [0 ])
0 commit comments