@@ -3132,7 +3132,7 @@ def in_ipython_frontend():
3132
3132
# working with straight ascii.
3133
3133
3134
3134
3135
- def _pprint_seq (seq , _nest_lvl = 0 , ** kwds ):
3135
+ def _pprint_seq (seq , _nest_lvl = 0 , max_seq_items = None , ** kwds ):
3136
3136
"""
3137
3137
internal. pprinter for iterables. you should probably use pprint_thing()
3138
3138
rather then calling this directly.
@@ -3144,7 +3144,10 @@ def _pprint_seq(seq, _nest_lvl=0, **kwds):
3144
3144
else :
3145
3145
fmt = u ("[%s]" ) if hasattr (seq , '__setitem__' ) else u ("(%s)" )
3146
3146
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 )
3148
3151
3149
3152
s = iter (seq )
3150
3153
r = []
@@ -3160,7 +3163,7 @@ def _pprint_seq(seq, _nest_lvl=0, **kwds):
3160
3163
return fmt % body
3161
3164
3162
3165
3163
- def _pprint_dict (seq , _nest_lvl = 0 , ** kwds ):
3166
+ def _pprint_dict (seq , _nest_lvl = 0 , max_seq_items = None , ** kwds ):
3164
3167
"""
3165
3168
internal. pprinter for iterables. you should probably use pprint_thing()
3166
3169
rather then calling this directly.
@@ -3170,7 +3173,10 @@ def _pprint_dict(seq, _nest_lvl=0, **kwds):
3170
3173
3171
3174
pfmt = u ("%s: %s" )
3172
3175
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 )
3174
3180
3175
3181
for k , v in list (seq .items ())[:nitems ]:
3176
3182
pairs .append (pfmt % (pprint_thing (k , _nest_lvl + 1 , ** kwds ),
@@ -3183,7 +3189,7 @@ def _pprint_dict(seq, _nest_lvl=0, **kwds):
3183
3189
3184
3190
3185
3191
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 ):
3187
3193
"""
3188
3194
This function is the sanctioned way of converting objects
3189
3195
to a unicode representation.
@@ -3202,6 +3208,8 @@ def pprint_thing(thing, _nest_lvl=0, escape_chars=None, default_escapes=False,
3202
3208
replacements
3203
3209
default_escapes : bool, default False
3204
3210
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
3205
3213
3206
3214
Returns
3207
3215
-------
@@ -3240,11 +3248,11 @@ def as_escaped_unicode(thing, escape_chars=escape_chars):
3240
3248
return compat .text_type (thing )
3241
3249
elif (isinstance (thing , dict ) and
3242
3250
_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 )
3244
3252
elif is_sequence (thing ) and _nest_lvl < \
3245
3253
get_option ("display.pprint_nest_depth" ):
3246
3254
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 )
3248
3256
elif isinstance (thing , compat .string_types ) and quote_strings :
3249
3257
if compat .PY3 :
3250
3258
fmt = "'%s'"
0 commit comments