17
17
from pandas .sparse .api import SparseSeries , SparseDataFrame , SparsePanel
18
18
from pandas .sparse .array import BlockIndex , IntIndex
19
19
from pandas .tseries .api import PeriodIndex , DatetimeIndex
20
- from pandas .core .common import adjoin , is_list_like
20
+ from pandas .core .base import StringMixin
21
+ from pandas .core .common import adjoin , is_list_like , pprint_thing
21
22
from pandas .core .algorithms import match , unique
22
23
from pandas .core .categorical import Categorical
23
24
from pandas .core .common import _asarray_tuplesafe
@@ -218,7 +219,7 @@ def read_hdf(path_or_buf, key, **kwargs):
218
219
# a passed store; user controls open/close
219
220
f (path_or_buf , False )
220
221
221
- class HDFStore (object ):
222
+ class HDFStore (StringMixin ):
222
223
"""
223
224
dict-like IO interface for storing pandas objects in PyTables
224
225
format.
@@ -315,8 +316,8 @@ def __contains__(self, key):
315
316
def __len__ (self ):
316
317
return len (self .groups ())
317
318
318
- def __repr__ (self ):
319
- output = '%s\n File path: %s\n ' % (type (self ), self ._path )
319
+ def __unicode__ (self ):
320
+ output = '%s\n File path: %s\n ' % (type (self ), pprint_thing ( self ._path ) )
320
321
321
322
if len (self .keys ()):
322
323
keys = []
@@ -326,11 +327,11 @@ def __repr__(self):
326
327
try :
327
328
s = self .get_storer (k )
328
329
if s is not None :
329
- keys .append (str (s .pathname or k ))
330
- values .append (str (s or 'invalid_HDFStore node' ))
331
- except ( Exception ), detail :
330
+ keys .append (pprint_thing (s .pathname or k ))
331
+ values .append (pprint_thing (s or 'invalid_HDFStore node' ))
332
+ except Exception as detail :
332
333
keys .append (k )
333
- values .append ("[invalid_HDFStore node: %s]" % str (detail ))
334
+ values .append ("[invalid_HDFStore node: %s]" % pprint_thing (detail ))
334
335
335
336
output += adjoin (12 , keys , values )
336
337
else :
@@ -984,7 +985,7 @@ def get_values(self):
984
985
self .close ()
985
986
return results
986
987
987
- class IndexCol (object ):
988
+ class IndexCol (StringMixin ):
988
989
""" an index column description class
989
990
990
991
Parameters
@@ -1050,10 +1051,9 @@ def set_table(self, table):
1050
1051
self .table = table
1051
1052
return self
1052
1053
1053
- def __repr__ (self ):
1054
- return "name->%s,cname->%s,axis->%s,pos->%s,kind->%s" % (self .name , self .cname , self .axis , self .pos , self .kind )
1055
-
1056
- __str__ = __repr__
1054
+ def __unicode__ (self ):
1055
+ temp = tuple (map (pprint_thing , (self .name , self .cname , self .axis , self .pos , self .kind )))
1056
+ return "name->%s,cname->%s,axis->%s,pos->%s,kind->%s" % temp
1057
1057
1058
1058
def __eq__ (self , other ):
1059
1059
""" compare 2 col items """
@@ -1570,7 +1570,7 @@ class GenericDataIndexableCol(DataIndexableCol):
1570
1570
def get_attr (self ):
1571
1571
pass
1572
1572
1573
- class Storer (object ):
1573
+ class Storer (StringMixin ):
1574
1574
""" represent an object in my store
1575
1575
facilitate read/write of various types of objects
1576
1576
this is an abstract base class
@@ -1610,19 +1610,16 @@ def set_version(self):
1610
1610
def pandas_type (self ):
1611
1611
return _ensure_decoded (getattr (self .group ._v_attrs , 'pandas_type' , None ))
1612
1612
1613
- def __repr__ (self ):
1614
- """ return a pretty representatgion of myself """
1613
+ def __unicode__ (self ):
1614
+ """ return a pretty representation of myself """
1615
1615
self .infer_axes ()
1616
1616
s = self .shape
1617
1617
if s is not None :
1618
1618
if isinstance (s , (list ,tuple )):
1619
- s = "[%s]" % ',' .join ([ str (x ) for x in s ])
1619
+ s = "[%s]" % ',' .join ([pprint_thing (x ) for x in s ])
1620
1620
return "%-12.12s (shape->%s)" % (self .pandas_type ,s )
1621
1621
return self .pandas_type
1622
1622
1623
- def __str__ (self ):
1624
- return self .__repr__ ()
1625
-
1626
1623
def set_object_info (self ):
1627
1624
""" set my pandas type & version """
1628
1625
self .attrs .pandas_type = self .pandas_kind
@@ -3435,7 +3432,7 @@ def _need_convert(kind):
3435
3432
return True
3436
3433
return False
3437
3434
3438
- class Term (object ):
3435
+ class Term (StringMixin ):
3439
3436
"""create a term object that holds a field, op, and value
3440
3437
3441
3438
Parameters
@@ -3540,10 +3537,9 @@ def __init__(self, field, op=None, value=None, queryables=None, encoding=None):
3540
3537
if len (self .q ):
3541
3538
self .eval ()
3542
3539
3543
- def __str__ (self ):
3544
- return "field->%s,op->%s,value->%s" % (self .field , self .op , self .value )
3545
-
3546
- __repr__ = __str__
3540
+ def __unicode__ (self ):
3541
+ attrs = map (pprint_thing , (self .field , self .op , self .value ))
3542
+ return "field->%s,op->%s,value->%s" % tuple (attrs )
3547
3543
3548
3544
@property
3549
3545
def is_valid (self ):
0 commit comments