Skip to content

Commit 76d4c49

Browse files
flying-sheepjreback
authored andcommitted
Use set literal syntax for set prettyprinting, #11215
1 parent a4843cb commit 76d4c49

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
@@ -31,6 +31,9 @@ API changes
3131
- min and max reductions on ``datetime64`` and ``timedelta64`` dtyped series now
3232
result in ``NaT`` and not ``nan`` (:issue:`11245`).
3333

34+
- Prettyprinting sets (e.g. in DataFrame cells) now uses set literal syntax (``{x, y}``) instead of
35+
Legacy Python syntax (``set([x, y])``) (:issue:`11215`)
36+
3437
.. _whatsnew_0171.deprecations:
3538

3639
Deprecations

pandas/core/common.py

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

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)