Skip to content

Commit b2138d4

Browse files
lodagrowesm
authored andcommitted
Series/DataFrame, make decision between full and short __repr__ configurable.
1 parent 3a528c4 commit b2138d4

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

pandas/core/common.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -346,21 +346,30 @@ def _try_sort(iterable):
346346
except Exception:
347347
return listed
348348

349-
def set_printoptions(precision=None, column_space=None):
349+
def set_printoptions(precision=None, column_space=None, max_rows=None,
350+
max_columns=None):
350351
"""
351352
Alter default behavior of DataFrame.toString
352353
353354
precision : int
354355
Floating point output precision
355356
column_space : int
356357
Default space for DataFrame columns, defaults to 12
358+
max_rows : int
359+
max_columns : int
360+
max_rows and max_columns are used in __repr__() methods to decide if
361+
to_string() or info() is used to render an object to a string.
357362
"""
358-
global _float_format, _column_space
363+
global _float_format, _column_space, _max_rows, _max_columns
359364
if precision is not None:
360365
float_format = '%.' + '%d' % precision + 'g'
361366
_float_format = lambda x: float_format % x
362367
if column_space is not None:
363368
_column_space = column_space
369+
if max_rows is not None:
370+
_max_rows = max_rows
371+
if max_columns is not None:
372+
_max_columns = max_columns
364373

365374
class EngFormatter(object):
366375
"""
@@ -467,6 +476,8 @@ def set_eng_float_format(precision=3, use_eng_prefix=False):
467476

468477
_float_format = lambda x: '%.4g' % x
469478
_column_space = 12
479+
_max_rows = 500
480+
_max_columns = 10
470481

471482
def _pfixed(s, space, na_rep=None, float_format=None):
472483
if isinstance(s, float):

pandas/core/frame.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
import numpy.ma as ma
2424

2525
from pandas.core.common import (isnull, notnull, PandasError, _try_sort,
26-
_default_index, _stringify, _maybe_upcast)
26+
_default_index, _stringify, _maybe_upcast,
27+
_max_rows, _max_columns)
2728
from pandas.core.daterange import DateRange
2829
from pandas.core.generic import NDFrame, AxisProperty
2930
from pandas.core.index import Index, MultiIndex, NULL_INDEX, _ensure_index
@@ -317,7 +318,8 @@ def __repr__(self):
317318
Return a string representation for a particular DataFrame
318319
"""
319320
buf = StringIO()
320-
if len(self.index) < 500 and len(self.columns) <= 10:
321+
if len(self.index) < com._max_rows and \
322+
len(self.columns) <= com._max_columns:
321323
self.to_string(buf=buf)
322324
else:
323325
self.info(buf=buf, verbose=self._verbose_info)

pandas/core/series.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -419,8 +419,8 @@ def __setslice__(self, i, j, value):
419419

420420
def __repr__(self):
421421
"""Clean string representation of a Series"""
422-
if len(self.index) > 500:
423-
result = self._tidy_repr(30)
422+
if len(self.index) > common._max_rows:
423+
result = self._tidy_repr(min(30, common._max_rows))
424424
elif len(self.index) > 0:
425425
result = self._get_repr(print_header=True,
426426
length=len(self) > 50,

0 commit comments

Comments
 (0)