diff --git a/pandas/core/common.py b/pandas/core/common.py index f9af37872d1b7..936f1d6357e4e 100644 --- a/pandas/core/common.py +++ b/pandas/core/common.py @@ -1073,6 +1073,14 @@ def _concat_compat(to_concat, axis=0): else: return np.concatenate(to_concat, axis=axis) +def in_interactive_session(): + """ check if we're running in an interactive shell + + returns True if running under python/ipython interactive shell + """ + import __main__ as main + return not hasattr(main, '__file__') + # Unicode consolidation # --------------------- # diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 4b826b98f4d18..2d15050b33906 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -581,13 +581,15 @@ def _need_info_repr_(self): else: # save us if (len(self.index) > max_rows or - len(self.columns) > terminal_width // 2): + (com.in_interactive_session() and + len(self.columns) > terminal_width // 2)): return True else: buf = StringIO() self.to_string(buf=buf) value = buf.getvalue() - if max([len(l) for l in value.split('\n')]) > terminal_width: + if (max([len(l) for l in value.split('\n')]) > terminal_width and + com.in_interactive_session()): return True else: return False