diff --git a/doc/source/whatsnew/v0.17.1.txt b/doc/source/whatsnew/v0.17.1.txt index 543eea399f447..3099b1553325b 100755 --- a/doc/source/whatsnew/v0.17.1.txt +++ b/doc/source/whatsnew/v0.17.1.txt @@ -28,6 +28,9 @@ Other Enhancements API changes ~~~~~~~~~~~ +- Prettyprinting sets (e.g. in DataFrame cells) now uses set literal syntax (``{x, y}``) instead of + Legacy Python syntax (``set([x, y])``). + .. _whatsnew_0171.deprecations: Deprecations diff --git a/pandas/core/common.py b/pandas/core/common.py index 2411925207696..279ff3b177954 100644 --- a/pandas/core/common.py +++ b/pandas/core/common.py @@ -3194,7 +3194,7 @@ def _pprint_seq(seq, _nest_lvl=0, max_seq_items=None, **kwds): bounds length of printed sequence, depending on options """ if isinstance(seq, set): - fmt = u("set([%s])") + fmt = u("{%s}") else: fmt = u("[%s]") if hasattr(seq, '__setitem__') else u("(%s)") diff --git a/pandas/tests/test_format.py b/pandas/tests/test_format.py index 14ff9e65c3e20..bf2cfc6216a60 100644 --- a/pandas/tests/test_format.py +++ b/pandas/tests/test_format.py @@ -191,13 +191,14 @@ def test_repr_chop_threshold(self): 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 - with option_context("display.max_seq_items",2000): self.assertTrue(len(com.pprint_thing(lrange(1000))) > 1000) with option_context("display.max_seq_items",5): - self.assertTrue(len(com.pprint_thing(lrange(1000)))< 100) + self.assertTrue(len(com.pprint_thing(lrange(1000))) < 100) + + def test_repr_set(self): + self.assertEqual(com.pprint_thing(set([1])), '{1}') def test_repr_is_valid_construction_code(self): # for the case of Index, where the repr is traditional rather then stylized