Skip to content

Commit c341820

Browse files
cpcloudy-p
authored and
y-p
committed
add a test for setting display.max_info_rows to None
1 parent 0fdad7e commit c341820

File tree

1 file changed

+30
-16
lines changed

1 file changed

+30
-16
lines changed

pandas/tests/test_format.py

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -480,28 +480,42 @@ def test_frame_info_encoding(self):
480480
fmt.set_printoptions(max_rows=200)
481481

482482
def test_large_frame_repr(self):
483-
old_max_rows = pd.get_option('display.max_rows')
484-
old_max_info_rows = pd.get_option('display.max_info_rows')
485-
486-
nrows, ncols = 3, 2
483+
def wrap_rows_options(f):
484+
def _f(*args, **kwargs):
485+
old_max_rows = pd.get_option('display.max_rows')
486+
old_max_info_rows = pd.get_option('display.max_info_rows')
487+
o = f(*args, **kwargs)
488+
pd.set_option('display.max_rows', old_max_rows)
489+
pd.set_option('display.max_info_rows', old_max_info_rows)
490+
return o
491+
return _f
492+
493+
@wrap_rows_options
494+
def test_setting(value, nrows=3, ncols=2):
495+
if value is None:
496+
expected_difference = 0
497+
elif isinstance(value, int):
498+
expected_difference = ncols
499+
else:
500+
raise ValueError("'value' must be int or None")
487501

488-
# need to set max rows so that we get an info-style repr
489-
pd.set_option('display.max_rows', nrows - 1)
490-
pd.set_option('display.max_info_rows', nrows)
502+
pd.set_option('display.max_rows', nrows - 1)
503+
pd.set_option('display.max_info_rows', value)
491504

492-
smallx = DataFrame(np.random.rand(nrows, ncols))
493-
repr_small = repr(smallx)
505+
smallx = DataFrame(np.random.rand(nrows, ncols))
506+
repr_small = repr(smallx)
494507

495-
bigx = DataFrame(np.random.rand(nrows + 1, ncols))
496-
repr_big = repr(bigx)
508+
bigx = DataFrame(np.random.rand(nrows + 1, ncols))
509+
repr_big = repr(bigx)
497510

498-
diff = len(repr_small.splitlines()) - len(repr_big.splitlines())
511+
diff = len(repr_small.splitlines()) - len(repr_big.splitlines())
499512

500-
# the difference in line count is the number of columns
501-
self.assertEqual(diff, ncols)
513+
# the difference in line count is the number of columns
514+
self.assertEqual(diff, expected_difference)
502515

503-
pd.set_option('display.max_rows', old_max_rows)
504-
pd.set_option('display.max_info_rows', old_max_info_rows)
516+
test_setting(None)
517+
test_setting(3)
518+
self.assertRaises(ValueError, test_setting, 'string')
505519

506520
def test_wide_repr(self):
507521
with option_context('mode.sim_interactive', True):

0 commit comments

Comments
 (0)