Skip to content

Commit 20529df

Browse files
y-pwesm
y-p
authored andcommitted
ENH: disable repr dependence on terminal width when running non-interactively. #1610
WARNING: nose runs non-interactively, so this is potential heisenbug material. but no changes to the test suite were needed, so I hope we're okay.
1 parent 687424e commit 20529df

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

pandas/core/common.py

+8
Original file line numberDiff line numberDiff line change
@@ -1073,6 +1073,14 @@ def _concat_compat(to_concat, axis=0):
10731073
else:
10741074
return np.concatenate(to_concat, axis=axis)
10751075

1076+
def in_interactive_session():
1077+
""" check if we're running in an interactive shell
1078+
1079+
returns True if running under python/ipython interactive shell
1080+
"""
1081+
import __main__ as main
1082+
return not hasattr(main, '__file__')
1083+
10761084
# Unicode consolidation
10771085
# ---------------------
10781086
#

pandas/core/frame.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -582,13 +582,15 @@ def _need_info_repr_(self):
582582
else:
583583
# save us
584584
if (len(self.index) > max_rows or
585-
len(self.columns) > terminal_width // 2):
585+
(com.in_interactive_session() and
586+
len(self.columns) > terminal_width // 2)):
586587
return True
587588
else:
588589
buf = StringIO()
589590
self.to_string(buf=buf)
590591
value = buf.getvalue()
591-
if max([len(l) for l in value.split('\n')]) > terminal_width:
592+
if (max([len(l) for l in value.split('\n')]) > terminal_width and
593+
com.in_interactive_session()):
592594
return True
593595
else:
594596
return False

0 commit comments

Comments
 (0)