Skip to content

Commit 0e245de

Browse files
quangngdmroeschkepre-commit-ci[bot]
authored
EHN: handle frozenset in pprint (#60828)
* Add test * handle frozenset * add whatsnew * Update doc/source/whatsnew/v3.0.0.rst Co-authored-by: Matthew Roeschke <[email protected]> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: Matthew Roeschke <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 57340ec commit 0e245de

File tree

3 files changed

+6
-0
lines changed

3 files changed

+6
-0
lines changed

doc/source/whatsnew/v3.0.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ Other enhancements
6868
- :meth:`Series.map` can now accept kwargs to pass on to func (:issue:`59814`)
6969
- :meth:`Series.str.get_dummies` now accepts a ``dtype`` parameter to specify the dtype of the resulting DataFrame (:issue:`47872`)
7070
- :meth:`pandas.concat` will raise a ``ValueError`` when ``ignore_index=True`` and ``keys`` is not ``None`` (:issue:`59274`)
71+
- :py:class:`frozenset` elements in pandas objects are now natively printed (:issue:`60690`)
7172
- Implemented :meth:`Series.str.isascii` and :meth:`Series.str.isascii` (:issue:`59091`)
7273
- Multiplying two :class:`DateOffset` objects will now raise a ``TypeError`` instead of a ``RecursionError`` (:issue:`59442`)
7374
- Restore support for reading Stata 104-format and enable reading 103-format dta files (:issue:`58554`)

pandas/io/formats/printing.py

+2
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ def _pprint_seq(
111111
"""
112112
if isinstance(seq, set):
113113
fmt = "{{{body}}}"
114+
elif isinstance(seq, frozenset):
115+
fmt = "frozenset({body})"
114116
else:
115117
fmt = "[{body}]" if hasattr(seq, "__setitem__") else "({body})"
116118

pandas/tests/io/formats/test_printing.py

+3
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ def test_repr_dict(self):
8282
def test_repr_mapping(self):
8383
assert printing.pprint_thing(MyMapping()) == "{'a': 4, 'b': 4}"
8484

85+
def test_repr_frozenset(self):
86+
assert printing.pprint_thing(frozenset([1, 2])) == "frozenset(1, 2)"
87+
8588

8689
class TestFormatBase:
8790
def test_adjoin(self):

0 commit comments

Comments
 (0)