def _repr_level_info(self): """ Returns a string representation of the footer.""" max_levels = (10 if get_option("display.max_levels") == 0 else get_option("display.max_levels")) level_strs = fmt.format_array(self.levels.get_values(), None) if len(level_strs) > max_levels: num = max_levels // 2 head = level_strs[:num] tail = level_strs[-(max_levels - num):] level_strs = head + ["..."] + tail # Strip all leading spaces, which format_array adds for columns... level_strs = [x.strip() for x in level_strs] levheader = "Levels (%d, %s): " % (len(self.levels), self.levels.dtype) width, height = get_terminal_size() max_width = (width if get_option("display.width") == 0 else get_option("display.width")) if com.in_ipython_frontend(): # 0 = no breaks max_width = 0 levstring = "" start = True cur_col_len = len(levheader) sep_len, sep = (3, " < ") if self.ordered else (2, ", ") for val in level_strs: if max_width != 0 and cur_col_len + sep_len + len(val) > max_width: levstring += "\n" + (" " * len(levheader)) cur_col_len = len(levheader) if not start: levstring += sep cur_col_len += len(val) levstring += val start = False # replace to simple save space by return levheader + "[" + levstring.replace(" < ... < ", " ... ") + "]"
def __unicode__(self): width, height = get_terminal_size() max_rows = height if get_option("display.max_rows") == 0 else get_option("display.max_rows") if len(self.labels) > (max_rows or 1000): result = self._tidy_repr(min(30, max_rows) - 4) elif len(self.labels) > 0: result = self._get_repr(length=len(self) > 50, name=True) else: result = "Categorical([], %s" % self._get_repr(name=True, length=False, footer=True) return result
def __unicode__(self): width, height = get_terminal_size() max_rows = (height if get_option("display.max_rows") == 0 else get_option("display.max_rows")) if len(self.labels) > (max_rows or 1000): result = self._tidy_repr(min(30, max_rows) - 4) elif len(self.labels) > 0: result = self._get_repr(length=len(self) > 50, name=True) else: result = 'Categorical([], %s' % self._get_repr( name=True, length=False, footer=True, ) return result
def __unicode__(self): """ Unicode representation. """ width, height = get_terminal_size() max_rows = (height if get_option("display.max_rows") == 0 else get_option("display.max_rows")) if len(self._codes) > (max_rows or 1000): result = self._tidy_repr(min(30, max_rows) - 4) elif len(self._codes) > 0: result = self._get_repr(length=len(self) > 50, name=True) else: result = 'Categorical([], %s' % self._get_repr(name=True, length=False, footer=True, ).replace("\n",", ") return result
def get_console_size(): """Return console size as tuple = (width, height). Returns (None,None) in non-interactive session. """ from pandas import get_option from pandas.core import common as com display_width = get_option('display.width') # deprecated. display_height = get_option('display.height', silent=True) # Consider # interactive shell terminal, can detect term size # interactive non-shell terminal (ipnb/ipqtconsole), cannot detect term # size non-interactive script, should disregard term size # in addition # width,height have default values, but setting to 'None' signals # should use Auto-Detection, But only in interactive shell-terminal. # Simple. yeah. if com.in_interactive_session(): if com.in_ipython_frontend(): # sane defaults for interactive non-shell terminal # match default for width,height in config_init from pandas.core.config import get_default_val terminal_width = get_default_val('display.width') terminal_height = get_default_val('display.height') else: # pure terminal terminal_width, terminal_height = get_terminal_size() else: terminal_width, terminal_height = None, None # Note if the User sets width/Height to None (auto-detection) # and we're in a script (non-inter), this will return (None,None) # caller needs to deal. return (display_width or terminal_width, display_height or terminal_height)
def _repr_categories_info(self): """ Returns a string representation of the footer.""" max_categories = (10 if get_option("display.max_categories") == 0 else get_option("display.max_categories")) category_strs = fmt.format_array(self.categories.get_values(), None) if len(category_strs) > max_categories: num = max_categories // 2 head = category_strs[:num] tail = category_strs[-(max_categories - num):] category_strs = head + ["..."] + tail # Strip all leading spaces, which format_array adds for columns... category_strs = [x.strip() for x in category_strs] levheader = "Categories (%d, %s): " % (len(self.categories), self.categories.dtype) width, height = get_terminal_size() max_width = (width if get_option("display.width") == 0 else get_option("display.width")) if com.in_ipython_frontend(): # 0 = no breaks max_width = 0 levstring = "" start = True cur_col_len = len(levheader) sep_len, sep = (3, " < ") if self.ordered else (2, ", ") for val in category_strs: if max_width != 0 and cur_col_len + sep_len + len(val) > max_width: levstring += "\n" + (" "* len(levheader)) cur_col_len = len(levheader) if not start: levstring += sep cur_col_len += len(val) levstring += val start = False # replace to simple save space by return levheader + "["+levstring.replace(" < ... < ", " ... ")+"]"
'B': [pd.Period('2011-01', freq='M'), pd.Period('2011-02-01', freq='D'), pd.Period('2011-03-01 09:00', freq='H'), pd.Period('2011-04', freq='M')], 'C': list('abcd')}) exp = (" A B C\n0 2013-01 2011-01 a\n" "1 2013-02 2011-02-01 b\n2 2013-03 2011-03-01 09:00 c\n" "3 2013-04 2011-04 d") #assert(str(df) == exp) # CORRECTIONS: remove 1 whitespace column before last column print("--> End: Test 4 test_period <--") # Test 5 test_repr_max_columns_max_rows print("--> Begin: Test 5 test_repr_max_columns_max_rows <--") term_width, term_height = get_terminal_size() if term_width < 10 or term_height < 10: raise nose.SkipTest("terminal size too small, " "{0} x {1}".format(term_width, term_height)) def mkframe(n): index = ['%05d' % i for i in range(n)] return pd.DataFrame(0, index, index) df6 = mkframe(6) df10 = mkframe(10) with pd.option_context('mode.sim_interactive', True): with pd.option_context('display.width', term_width * 2): with pd.option_context('display.max_rows', 5, 'display.max_columns', 5): assert(not has_expanded_repr(mkframe(4)))