Skip to content
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

API: change default for show_dimensions to 'truncate', related (GH7108, GH6547) #7122

Merged
merged 1 commit into from
May 14, 2014
Merged
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
2 changes: 1 addition & 1 deletion pandas/core/config_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ def mpl_style_cb(key):
cf.register_option('encoding', detect_console_encoding(), pc_encoding_doc,
validator=is_text)
cf.register_option('expand_frame_repr', True, pc_expand_repr_doc)
cf.register_option('show_dimensions', True, pc_show_dimensions_doc,
cf.register_option('show_dimensions', 'truncate', pc_show_dimensions_doc,
validator=is_one_of_factory([True, False, 'truncate']))
cf.register_option('chop_threshold', None, pc_chop_threshold_doc)
cf.register_option('max_seq_items', 100, pc_max_seq_items)
Expand Down
16 changes: 9 additions & 7 deletions pandas/tests/test_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,16 +141,16 @@ def test_repr_truncation(self):
def test_repr_chop_threshold(self):
df = DataFrame([[0.1, 0.5],[0.5, -0.1]])
pd.reset_option("display.chop_threshold") # default None
self.assertEqual(repr(df), ' 0 1\n0 0.1 0.5\n1 0.5 -0.1\n\n[2 rows x 2 columns]')
self.assertEqual(repr(df), ' 0 1\n0 0.1 0.5\n1 0.5 -0.1')

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

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

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

def test_repr_obeys_max_seq_limit(self):
import pandas.core.common as com
Expand Down Expand Up @@ -197,7 +197,8 @@ def test_expand_frame_repr(self):
with option_context('mode.sim_interactive', True):
with option_context('display.max_columns', 10,
'display.width',20,
'display.max_rows', 20):
'display.max_rows', 20,
'display.show_dimensions', True):
with option_context('display.expand_frame_repr', True):
self.assertFalse(has_truncated_repr(df_small))
self.assertFalse(has_expanded_repr(df_small))
Expand Down Expand Up @@ -789,7 +790,7 @@ def test_pprint_thing(self):
self.assertTrue(not "\t" in pp_t("a\tb", escape_chars=("\t",)))

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

self.assertEqual(len(rep_str.splitlines()), 22)
self.assertEqual(len(rep_str.splitlines()), 20)

def test_wide_repr_named(self):
with option_context('mode.sim_interactive', True):
Expand Down Expand Up @@ -1458,6 +1459,7 @@ def test_repr_html(self):
self.reset_display_options()

df = DataFrame([[1, 2], [3, 4]])
fmt.set_option('display.show_dimensions', True)
self.assertTrue('2 rows' in df._repr_html_())
fmt.set_option('display.show_dimensions', False)
self.assertFalse('2 rows' in df._repr_html_())
Expand Down
10 changes: 6 additions & 4 deletions pandas/tests/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -4354,12 +4354,14 @@ def test_repr(self):

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

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

self.reset_display_options()
with pd.option_context('display.show_dimensions', 'truncate'):
self.assertFalse("2 rows x 2 columns" in repr(df))

@slow
def test_repr_big(self):
Expand Down