8000 Applying max_colwidth to the DataFrame index (#7856) by tiagoantao · Pull Request #8954 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content

Applying max_colwidth to the DataFrame index (#7856) #8954

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Bug on representation of index (#7856): refactored test
  • Loading branch information
tiagoantao committed Mar 9, 2015
commit 7228df2eb9fc8ce58445bfb0a90efcd32eb4e3d4
15 changes: 15 additions & 0 deletions pandas/tests/test_format.py
8000
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,21 @@ def mkframe(n):
com.pprint_thing(df._repr_fits_horizontal_())
self.assertTrue(has_expanded_repr(df))

def test_str_max_colwidth(self):
# GH 7856
df = pd.DataFrame([{'a': 'foo', 'b': 'bar',
'c': 'uncomfortably long line with lots of stuff',
'd': 1},
{'a': 'foo', 'b': 'bar', 'c': 'stuff', 'd': 1}])
df.set_index(['a', 'b', 'c'])
self.assertTrue(str(df) == ' a b c d\n'
'0 foo bar uncomfortably long line with lots of stuff 1\n'
'1 foo bar stuff 1')
with option_context('max_colwidth', 20):
self.assertTrue(str(df) == ' a b c d\n'
'0 foo bar uncomfortably lo... 1\n'
'1 foo bar stuff 1')

def test_auto_detect(self):
term_width, term_height = get_terminal_size()
fac = 1.05 # Arbitrary large factor to exceed term widht
Expand Down
18 changes: 0 additions & 18 deletions pandas/tests/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -4815,24 +4815,6 @@ def test_repr_unicode(self):
result = repr(df)
self.assertEqual(result.split('\n')[0].rstrip(), ex_top)

def test_str_max_colwidth(self):
# GH 7856
curr_max_colwidth = pd.get_option('max_colwidth')
# As we change a global option, we save it
df = pd.DataFrame([{'a': 'foo', 'b': 'bar',
'c': 'uncomfortably long line with lots of stuff',
'd': 1},
{'a': 'foo', 'b': 'bar', 'c': 'stuff', 'd': 1}])
df.set_index(['a', 'b', 'c'])
assert(str(df) == ' a b c d\n'
'0 foo bar uncomfortably long line with lots of stuff 1\n'
'1 foo bar stuff 1')
pd.set_option('max_colwidth', 20)
assert(str(df) == ' a b c d\n'
'0 foo bar uncomfortably lo... 1\n'
'1 foo bar stuff 1')
pd.set_option('max_colwidth', curr_max_colwidth)

def test_unicode_string_with_unicode(self):
df = DataFrame({'A': [u("\u05d0")]})

Expand Down
0