|
19 | 19 | from pandas.util.py3compat import lzip
|
20 | 20 | import pandas.core.format as fmt
|
21 | 21 | import pandas.util.testing as tm
|
| 22 | +from pandas.util.terminal import get_terminal_size |
22 | 23 | import pandas
|
23 | 24 | import pandas as pd
|
24 | 25 | from pandas.core.config import (set_option, get_option,
|
@@ -144,6 +145,53 @@ def test_repr_no_backslash(self):
|
144 | 145 | df = DataFrame(np.random.randn(10, 4))
|
145 | 146 | self.assertTrue('\\' not in repr(df))
|
146 | 147 |
|
| 148 | + def test_repr_max_columns_max_rows(self): |
| 149 | + import pandas.core.common as com |
| 150 | + original_in_interactive_session = com.in_interactive_session |
| 151 | + com.in_interactive_session = lambda: True |
| 152 | + |
| 153 | + term_width, term_height = get_terminal_size() |
| 154 | + if term_width < 10 or term_height < 10: |
| 155 | + raise nose.SkipTest |
| 156 | + |
| 157 | + def repr_is_info_view(n): |
| 158 | + index = ['%05d' % i for i in range(n)] |
| 159 | + df = DataFrame(0, index, index) |
| 160 | + r = repr(df) |
| 161 | + nlines = len(r.split('\n')) |
| 162 | + return nlines > n + 2 |
| 163 | + |
| 164 | + with option_context('display.line_width', term_width * 2): |
| 165 | + with option_context('display.max_rows', 5, |
| 166 | + 'display.max_columns', 5): |
| 167 | + self.assertFalse(repr_is_info_view(4)) |
| 168 | + self.assertFalse(repr_is_info_view(5)) |
| 169 | + self.assertTrue(repr_is_info_view(6)) |
| 170 | + |
| 171 | + with option_context('display.max_rows', 10, |
| 172 | + 'display.max_columns', 5): |
| 173 | + self.assertFalse(repr_is_info_view(5)) |
| 174 | + self.assertTrue(repr_is_info_view(6)) |
| 175 | + |
| 176 | + with option_context('display.max_rows', 5, |
| 177 | + 'display.max_columns', 10): |
| 178 | + self.assertFalse(repr_is_info_view(5)) |
| 179 | + self.assertTrue(repr_is_info_view(6)) |
| 180 | + |
| 181 | + with option_context('display.max_rows', 0, |
| 182 | + 'display.max_columns', term_height): |
| 183 | + self.assertFalse(repr_is_info_view(term_height - 2)) |
| 184 | + self.assertTrue(repr_is_info_view(term_height + 1)) |
| 185 | + |
| 186 | + with option_context('display.max_rows', term_height * 2, |
| 187 | + 'display.max_columns', 0): |
| 188 | + self.assertTrue(com.in_interactive_session()) |
| 189 | + n = (term_width + 2) // 7 |
| 190 | + self.assertFalse(repr_is_info_view(n - 1)) |
| 191 | + self.assertTrue(repr_is_info_view(n + 1)) |
| 192 | + |
| 193 | + com.in_interactive_session = original_in_interactive_session |
| 194 | + |
147 | 195 | def test_to_string_repr_unicode(self):
|
148 | 196 | buf = StringIO()
|
149 | 197 |
|
|
0 commit comments