Skip to content

Commit d7b2fa7

Browse files
committed
Merge pull request #7122 from jreback/show_dim_default
API: change default for show_dimensions to 'truncate', related (GH7108, GH6547)
2 parents 3c57381 + 61cf9c7 commit d7b2fa7

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

pandas/core/config_init.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ def mpl_style_cb(key):
249249
cf.register_option('encoding', detect_console_encoding(), pc_encoding_doc,
250250
validator=is_text)
251251
cf.register_option('expand_frame_repr', True, pc_expand_repr_doc)
252-
cf.register_option('show_dimensions', True, pc_show_dimensions_doc,
252+
cf.register_option('show_dimensions', 'truncate', pc_show_dimensions_doc,
253253
validator=is_one_of_factory([True, False, 'truncate']))
254254
cf.register_option('chop_threshold', None, pc_chop_threshold_doc)
255255
cf.register_option('max_seq_items', 100, pc_max_seq_items)

pandas/tests/test_format.py

+9-7
Original file line numberDiff line numberDiff line change
@@ -141,16 +141,16 @@ def test_repr_truncation(self):
141141
def test_repr_chop_threshold(self):
142142
df = DataFrame([[0.1, 0.5],[0.5, -0.1]])
143143
pd.reset_option("display.chop_threshold") # default None
144-
self.assertEqual(repr(df), ' 0 1\n0 0.1 0.5\n1 0.5 -0.1\n\n[2 rows x 2 columns]')
144+
self.assertEqual(repr(df), ' 0 1\n0 0.1 0.5\n1 0.5 -0.1')
145145

146146
with option_context("display.chop_threshold", 0.2 ):
147-
self.assertEqual(repr(df), ' 0 1\n0 0.0 0.5\n1 0.5 0.0\n\n[2 rows x 2 columns]')
147+
self.assertEqual(repr(df), ' 0 1\n0 0.0 0.5\n1 0.5 0.0')
148148

149149
with option_context("display.chop_threshold", 0.6 ):
150-
self.assertEqual(repr(df), ' 0 1\n0 0 0\n1 0 0\n\n[2 rows x 2 columns]')
150+
self.assertEqual(repr(df), ' 0 1\n0 0 0\n1 0 0')
151151

152152
with option_context("display.chop_threshold", None ):
153-
self.assertEqual(repr(df), ' 0 1\n0 0.1 0.5\n1 0.5 -0.1\n\n[2 rows x 2 columns]')
153+
self.assertEqual(repr(df), ' 0 1\n0 0.1 0.5\n1 0.5 -0.1')
154154

155155
def test_repr_obeys_max_seq_limit(self):
156156
import pandas.core.common as com
@@ -197,7 +197,8 @@ def test_expand_frame_repr(self):
197197
with option_context('mode.sim_interactive', True):
198198
with option_context('display.max_columns', 10,
199199
'display.width',20,
200-
'display.max_rows', 20):
200+
'display.max_rows', 20,
201+
'display.show_dimensions', True):
201202
with option_context('display.expand_frame_repr', True):
202203
self.assertFalse(has_truncated_repr(df_small))
203204
self.assertFalse(has_expanded_repr(df_small))
@@ -789,7 +790,7 @@ def test_pprint_thing(self):
789790
self.assertTrue(not "\t" in pp_t("a\tb", escape_chars=("\t",)))
790791

791792
def test_wide_repr(self):
792-
with option_context('mode.sim_interactive', True):
793+
with option_context('mode.sim_interactive', True, 'display.show_dimensions', True):
793794
col = lambda l, k: [tm.rands(k) for _ in range(l)]
794795
max_cols = get_option('display.max_columns')
795796
df = DataFrame([col(max_cols - 1, 25) for _ in range(10)])
@@ -812,7 +813,7 @@ def test_wide_repr_wide_columns(self):
812813
df = DataFrame(randn(5, 3), columns=['a' * 90, 'b' * 90, 'c' * 90])
813814
rep_str = repr(df)
814815

815-
self.assertEqual(len(rep_str.splitlines()), 22)
816+
self.assertEqual(len(rep_str.splitlines()), 20)
816817

817818
def test_wide_repr_named(self):
818819
with option_context('mode.sim_interactive', True):
@@ -1458,6 +1459,7 @@ def test_repr_html(self):
14581459
self.reset_display_options()
14591460

14601461
df = DataFrame([[1, 2], [3, 4]])
1462+
fmt.set_option('display.show_dimensions', True)
14611463
self.assertTrue('2 rows' in df._repr_html_())
14621464
fmt.set_option('display.show_dimensions', False)
14631465
self.assertFalse('2 rows' in df._repr_html_())

pandas/tests/test_frame.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -4354,12 +4354,14 @@ def test_repr(self):
43544354

43554355
def test_repr_dimensions(self):
43564356
df = DataFrame([[1, 2,], [3, 4]])
4357-
self.assertTrue("2 rows x 2 columns" in repr(df))
4357+
with pd.option_context('display.show_dimensions', True):
4358+
self.assertTrue("2 rows x 2 columns" in repr(df))
43584359

4359-
fmt.set_option('display.show_dimensions', False)
4360-
self.assertFalse("2 rows x 2 columns" in repr(df))
4360+
with pd.option_context('display.show_dimensions', False):
4361+
self.assertFalse("2 rows x 2 columns" in repr(df))
43614362

4362-
self.reset_display_options()
4363+
with pd.option_context('display.show_dimensions', 'truncate'):
4364+
self.assertFalse("2 rows x 2 columns" in repr(df))
43634365

43644366
@slow
43654367
def test_repr_big(self):

0 commit comments

Comments
 (0)