Skip to content

Commit 9c4be01

Browse files
committed
Use set literal syntax for set prettyprinting
1 parent 26db172 commit 9c4be01

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

doc/source/whatsnew/v0.17.1.txt

+3
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ Other Enhancements
2828
API changes
2929
~~~~~~~~~~~
3030

31+
- Prettyprinting sets (e.g. in DataFrame cells) now uses set literal syntax (``{x, y}``) instead of
32+
Legacy Python syntax (``set([x, y])``).
33+
3134
.. _whatsnew_0171.deprecations:
3235

3336
Deprecations

pandas/core/common.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3194,7 +3194,7 @@ def _pprint_seq(seq, _nest_lvl=0, max_seq_items=None, **kwds):
31943194
bounds length of printed sequence, depending on options
31953195
"""
31963196
if isinstance(seq, set):
3197-
fmt = u("set([%s])")
3197+
fmt = u("{%s}")
31983198
else:
31993199
fmt = u("[%s]") if hasattr(seq, '__setitem__') else u("(%s)")
32003200

pandas/tests/test_format.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -191,13 +191,14 @@ def test_repr_chop_threshold(self):
191191
self.assertEqual(repr(df), ' 0 1\n0 0.1 0.5\n1 0.5 -0.1')
192192

193193
def test_repr_obeys_max_seq_limit(self):
194-
import pandas.core.common as com
195-
196194
with option_context("display.max_seq_items",2000):
197195
self.assertTrue(len(com.pprint_thing(lrange(1000))) > 1000)
198196

199197
with option_context("display.max_seq_items",5):
200-
self.assertTrue(len(com.pprint_thing(lrange(1000)))< 100)
198+
self.assertTrue(len(com.pprint_thing(lrange(1000))) < 100)
199+
200+
def test_repr_set(self):
201+
self.assertEqual(com.pprint_thing(set([1])), '{1}')
201202

202203
def test_repr_is_valid_construction_code(self):
203204
# for the case of Index, where the repr is traditional rather then stylized

0 commit comments

Comments
 (0)