Skip to content

Commit 241d2bf

Browse files
committed
fixup for CategoricalIndex merge
1 parent 3e4f8f0 commit 241d2bf

File tree

2 files changed

+31
-31
lines changed

2 files changed

+31
-31
lines changed

pandas/core/common.py

+15-7
Original file line numberDiff line numberDiff line change
@@ -3132,7 +3132,7 @@ def in_ipython_frontend():
31323132
# working with straight ascii.
31333133

31343134

3135-
def _pprint_seq(seq, _nest_lvl=0, **kwds):
3135+
def _pprint_seq(seq, _nest_lvl=0, max_seq_items=None, **kwds):
31363136
"""
31373137
internal. pprinter for iterables. you should probably use pprint_thing()
31383138
rather then calling this directly.
@@ -3144,7 +3144,10 @@ def _pprint_seq(seq, _nest_lvl=0, **kwds):
31443144
else:
31453145
fmt = u("[%s]") if hasattr(seq, '__setitem__') else u("(%s)")
31463146

3147-
nitems = get_option("max_seq_items") or len(seq)
3147+
if max_seq_items is False:
3148+
nitems = len(seq)
3149+
else:
3150+
nitems = max_seq_items or get_option("max_seq_items") or len(seq)
31483151

31493152
s = iter(seq)
31503153
r = []
@@ -3160,7 +3163,7 @@ def _pprint_seq(seq, _nest_lvl=0, **kwds):
31603163
return fmt % body
31613164

31623165

3163-
def _pprint_dict(seq, _nest_lvl=0, **kwds):
3166+
def _pprint_dict(seq, _nest_lvl=0, max_seq_items=None, **kwds):
31643167
"""
31653168
internal. pprinter for iterables. you should probably use pprint_thing()
31663169
rather then calling this directly.
@@ -3170,7 +3173,10 @@ def _pprint_dict(seq, _nest_lvl=0, **kwds):
31703173

31713174
pfmt = u("%s: %s")
31723175

3173-
nitems = get_option("max_seq_items") or len(seq)
3176+
if max_seq_items is False:
3177+
nitems = len(seq)
3178+
else:
3179+
nitems = max_seq_items or get_option("max_seq_items") or len(seq)
31743180

31753181
for k, v in list(seq.items())[:nitems]:
31763182
pairs.append(pfmt % (pprint_thing(k, _nest_lvl + 1, **kwds),
@@ -3183,7 +3189,7 @@ def _pprint_dict(seq, _nest_lvl=0, **kwds):
31833189

31843190

31853191
def pprint_thing(thing, _nest_lvl=0, escape_chars=None, default_escapes=False,
3186-
quote_strings=False):
3192+
quote_strings=False, max_seq_items=None):
31873193
"""
31883194
This function is the sanctioned way of converting objects
31893195
to a unicode representation.
@@ -3202,6 +3208,8 @@ def pprint_thing(thing, _nest_lvl=0, escape_chars=None, default_escapes=False,
32023208
replacements
32033209
default_escapes : bool, default False
32043210
Whether the input escape characters replaces or adds to the defaults
3211+
max_seq_items : False, int, default None
3212+
Pass thru to other pretty printers to limit sequence printing
32053213
32063214
Returns
32073215
-------
@@ -3240,11 +3248,11 @@ def as_escaped_unicode(thing, escape_chars=escape_chars):
32403248
return compat.text_type(thing)
32413249
elif (isinstance(thing, dict) and
32423250
_nest_lvl < get_option("display.pprint_nest_depth")):
3243-
result = _pprint_dict(thing, _nest_lvl, quote_strings=True)
3251+
result = _pprint_dict(thing, _nest_lvl, quote_strings=True, max_seq_items=max_seq_items)
32443252
elif is_sequence(thing) and _nest_lvl < \
32453253
get_option("display.pprint_nest_depth"):
32463254
result = _pprint_seq(thing, _nest_lvl, escape_chars=escape_chars,
3247-
quote_strings=quote_strings)
3255+
quote_strings=quote_strings, max_seq_items=max_seq_items)
32483256
elif isinstance(thing, compat.string_types) and quote_strings:
32493257
if compat.PY3:
32503258
fmt = "'%s'"

pandas/core/index.py

+16-24
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@
2626
from pandas.io.common import PerformanceWarning
2727

2828
# simplify
29-
default_pprint = lambda x: com.pprint_thing(x, escape_chars=('\t', '\r', '\n'),
30-
quote_strings=True)
29+
default_pprint = lambda x, max_seq_items=None: com.pprint_thing(x,
30+
escape_chars=('\t', '\r', '\n'),
31+
quote_strings=True,
32+
max_seq_items=max_seq_items)
3133

3234

3335
__all__ = ['Index']
@@ -2852,32 +2854,22 @@ def equals(self, other):
28522854

28532855
return False
28542856

2855-
def __unicode__(self):
2857+
def _format_attrs(self):
28562858
"""
2857-
Return a string representation for this object.
2858-
2859-
Invoked by unicode(df) in py2 only. Yields a Unicode String in both
2860-
py2/py3.
2859+
Return a list of tuples of the (attr,formatted_value)
28612860
"""
2861+
attrs = [('categories', default_pprint(self.categories, max_seq_items=False)),
2862+
('ordered',self.ordered)]
2863+
if self.name is not None:
2864+
attrs.append(('name',default_pprint(self.name)))
2865+
attrs.append(('dtype',"'%s'" % self.dtype))
2866+
return attrs
28622867

2863-
# currently doesn't use the display.max_categories, or display.max_seq_len
2864-
# for head/tail printing
2865-
values = default_pprint(self.values.get_values())
2866-
cats = default_pprint(self.categories.get_values())
2867-
space = ' ' * (len(self.__class__.__name__) + 1)
2868-
name = self.name
2869-
if name is not None:
2870-
name = default_pprint(name)
2871-
2872-
result = u("{klass}({values},\n{space}categories={categories},\n{space}ordered={ordered},\n{space}name={name})").format(
2873-
klass=self.__class__.__name__,
2874-
values=values,
2875-
categories=cats,
2876-
ordered=self.ordered,
2877-
name=name,
2878-
space=space)
2868+
def _format_space(self):
2869+
return "\n%s" % (' ' * (len(self.__class__.__name__) + 1))
28792870

2880-
return result
2871+
def _format_data(self):
2872+
return default_pprint(self.values.get_values(), max_seq_items=False)
28812873

28822874
@property
28832875
def inferred_type(self):

0 commit comments

Comments
 (0)