Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion pandas/core/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,11 @@ def just(x):
except UnicodeError:
eff_len = max_len

return justfunc(x[:eff_len], eff_len)
if conf_max is not None:
if (conf_max > 3) & (_strlen(x) > max_len):
x = x[:eff_len - 3] + '...'

return justfunc(x, eff_len)

return [just(x) for x in strings]

Expand Down
20 changes: 20 additions & 0 deletions pandas/tests/test_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,26 @@ def test_repr_tuples(self):
repr(df)
df.to_string(col_space=10, buf=buf)

def test_repr_truncation(self):
max_len = 20
fmt.print_config.max_colwidth = max_len
df = DataFrame({'A': np.random.randn(10),
'B': [tm.rands(np.random.randint(max_len - 1,
max_len + 1)) for i in range(10)]})
r = repr(df)
r = r[r.find('\n') + 1:]
for line, value in zip(r.split('\n'), df['B']):
if fmt._strlen(value) + 1 > max_len:
self.assert_('...' in line)
else:
self.assert_('...' not in line)

fmt.print_config.max_colwidth = None
self.assert_('...' not in repr(df))

fmt.print_config.max_colwidth = max_len + 2
self.assert_('...' not in repr(df))

def test_to_string_repr_unicode(self):
buf = StringIO()

Expand Down